Bug - Fixed Escape quotes in to_json() to avoid corrupt JSON data

zarqon

Well-known member
If you have a map thismap of string[string], and any one of those strings contains a double quote, the result of ASH's to_json(thismap) will end up corrupt since it does not escape quotes in the data.

I can write a routine to check all the strings for quotes and escape them before calling to_json(), but it seems like this is something that ought to be handled in the function itself. If Joe Scripter calls to_json() on some data, he would almost certainly expect the result to be valid JSON. He wouldn't expect the function to stop working if that data contained a certain punctuation mark.
 

Veracity

Developer
Staff member
I had no idea ASH had that function. Seems that hola added it in revision 11198 on 26 Jun 2012.
"Add naive implementation of to_json() for all types".

Huh.
 

Veracity

Developer
Staff member
We have a JSON reader/writer already in our code tree from JSON.org in lib/org/json/*.java.

JSONStringer.java sez:

* JSONStringer provides a quick and convenient way of producing JSON text.
* The texts produced strictly conform to JSON syntax rules. No whitespace is
* added, so the results are ready for transmission or storage. Each instance of
* JSONStringer can produce one JSON text.
Seems like that's the right thing to use to make a non-naive implementation.
 

Veracity

Developer
Staff member
I'm changing this from Feat Request to Bug Report; if we write JSON, formatting strings incorrectly is a bug.
 
Top