ConorBaumgart ConorBaumgart - 1 year ago 74
JSON Question

JSON doesn't seem to like '4D '

I'm running into a strange issue in Coldfusion using the serializeJSON and deserializeJSON functions. When I do the following:

<cfdump var="#deserializeJSON(serializeJSON('4D '))#">

and load the page, I get an error that reads 'JSON parsing failure at character 2:'D' in 4D'. When I change the D so that the input looks something like '4E ' the page loads fine, but when I change the number so that the input reads something like '5D ' I get the same error. I think I may be accidentally entering an escape character but I don't know enough about character encoding to say that with confidence. Does anyone have any idea about why this might happen?

Answer Source

It appears you are using ColdFusion 9.x as this issue has been fixed in later versions of ColdFusion.

This same issue has been asked before, please see Coldfusion JSON serialization inconsistency

Any entirely numeric string with trailing D or F followed by whitespace [..results in an error when deserialized].

JSON parsing failure at character 9:'D' in {"wtf":4D }

The parser trims and checks if the last character is D or F (double or float) and strips it. If the remaining characters are numeric, no quotes are added. If you don't have trailing whitespace, it works perfectly. The specific combo of number, D|F and spaces trips it up.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download