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."
7 years, 3 months ago
02 Jun 2011 05:39 CEST
|Site News Item: