PHP json_encode encoding numbers as strings

PHP json_encode encoding numbers as strings

I am having one problem with the PHP json_encode function. It encodes numbers as strings, e.g. array('id'=> 3) becomes "{["id": "3",...) When js encounters these values, it interprets them as st…


Escaping/encoding single quotes in JSON encoded HTML5 data attributes

In PHP, I use json_encode() to echo arrays in HTML5 data attributes. As JSON requires-and json_encode() generates-values encapsulated by double quotes. I therefor wrap my data attributes with sin…


PHP json_encode-JSON_FORCE_OBJECT mixed object and array output

I have a PHP data structure I want to JSON encode. It can contain a number of empty arrays, some of which need to be encoded as arrays and some of which need to be encoded as objects. For instance, le…



PHP: How to encode infinity or NaN numbers to JSON?

Apparently, infinity and NaN are not a part of JSON specification, so this PHP code: $numbers=array(); $numbers['positive_infinity']=+INF; $numbers['negative_infinity']=-INF; $numbers['not_a_…


php - Laravel 5 controller sending JSON integer as string

On my development server the JSON response from the Laravel 5 controller shows the data in the correct types. e.g imdb_rating: 7.6 imdb_votes: 6271 But on the production server, the JSON response is…




json_numeric_check json json_encode encode value decode and utf8 string return