I’ve a quick question regarding JSON. I just started getting familiar with it and it seems to me similar to XML, a technique in storing and transferring data in a universal/open way.
My question is data integrity. It seems to me that, for example, a JSON output from my PHP application looks like this:
{"stat":"ok","statMsg":"json works"}
Now unlike XML it uses <> characters. JSON seems to use more common characters, like quotes and double quotes etc.
That makes me wonder, is JSON format treated like plain text by the parser? What if the parser encounters “delimiting” characters such as slashes, double quotes etc?
I do a lot of data handling where it is imperative to MAINTAIN the textual data while being passed around, quotes and all (dealing with code and other stuff) and I’m afraid to use JSON as my data may break the format.
Well xml files are also considered “plain text” by the parser. Just like XML in JSON special characters should be escaped (remember
&,><and many more?). So as long as you or the library you are using take care of that you should not worry. Of course using a library for that kind of stuff is the recommended way. For php usejson_encodefor instance.I personally think that JSON’s escaping is simpler as it is closer to the way one escapes special characters in strings in many languages.
Also have a look here. Only a very limited set of chars actually needs to be escaped.