Welcome to Inkbunny...
Allowed ratings
To view member-only content, create an account. ( Hide )
Inkbunny

[Inkbunny API] Typecasting JSON from the API

Hi everyone

Developers working with the API will notice that the types returned for values in JSON mode can often be unpredictable.

Sometimes they are string or integer types when you were expecting the opposite.

This is because on the server side (with PHP and Postgresql) types don't mean too much. Values pulled from the database are always strings (even when they come from integer columns because that's how Postgres returns them to PHP). We don't then worry about what type each column was before we spit results out in JSON mode.

So you need to make sure all the values incoming are typecast the way you want them. This is also good for validation and general sanity checking of incoming data.

And of course you will have this problem anyway if you are dealing with XML output mode, where everything is a string.

Sorry if that's inconvenient! But the fix on our side would be a heck of a lot of ongoing work. We'd have to look at every single column and variable that the entire codebase can return and have to decide if it should be cast to string or int before sending it as JSON. I don't want to do that. ;.;

A new line has been added to the API wiki:
"You must type-cast variables yourself when they are returned by the API. In JSON mode, sometimes they will be strings or integers when you least expect it."

Thanks!

IB
Viewed: 125 times
Added: 12 years, 11 months ago
Site News Item: yes
Commenting Locked
 
jonhskitsune
12 years, 11 months ago
Cute Bunny talking hard! *pets him* =3
Inkbunny
12 years, 11 months ago
Hey! Respect my authoritah! D:
Flygon
12 years, 11 months ago
But you look like the Energizer bunnies evil cousin!
jonhskitsune
12 years, 11 months ago
You know we Love you =3
New Comment:
Move reply box to top
Log in or create an account to comment.