Various third-party companies force us to use non-standard code and produce non-standard output.
We use standard json_encode() to output the JSON variable in JS / HTML, which looks like this:
"custom":{"1":2,"2":7,"3":5}
Now they tell us that this does not work for them, they need it like this:
"custom":{"1":"2","2":"7","3":"5"}
Can I get PHP to wrap quotes around arround numbers? Maybe using cast (string) when we create an object before encoding?
Basically, we need the opposite of the following bitflag parameter:
JSON_NUMERIC_CHECK (integer)
Encodes numeric strings as numbers. Available since PHP 5.3.3.
But I doubt that it exists.
json php
DanFromGermany
source share