Here is a handy tip about PHP’s json_encode function.
In some cases numeric data may appear as numeric strings, for example 1 as “1”. While consuming the json data on a client app that would mean an extra parsing to get for example an int from the string.
The solution is to simply use an extra option (JSON_NUMERIC_CHECK) on the json_encode function call:
<?php echo json_encode($data, JSON_NUMERIC_CHECK); ?>
I have to point out that this option requires a PHP version of 5.3.3 or higher.
Note that this doesn’t work if json_encode thinks a string is a scientific number and it’s very large. e.g. 82E38492849 causes the error “json_encode(): double INF does not conform to the JSON spec, encoded as 0”
I helped. Thanks a lot.
“IT helped”, I meant.
Yes, +1 Erik,
Here is the office bug reported
https://bugs.php.net/bug.php?id=64695
It also is dangerous if you have a phone number with +, e.g. +3712345678 because JSON_NUMERIC_CHECK will treat this as number and remove +
This also helped me out. Thanks.
can’t believe find my answer in an old thread.. thank you very much!