Clarifying JSON

I've used JSON for a while now in my web applications, but I've recently discovered that I've had a few misunderstandings and thought I would share them in case others had similar misunderstandings.

In a recent JSConf talk, Douglas Crockford, who defined and popularized JSON as a data interchange format, talks about how he got the naming of JSON wrong. It's pretty entertaining so I would just recommend watching the one-minute segment on YouTube where talks about this. Essentially, he says it's confusing to call it Javascript, since other programming languages can use it.

Misconceptions about JSON:

  • You can JSON.stringify can convert any value in Javascript to a string that stores it in the JSON format
  • When you do JSON.parse, you don't necessarily receive an object. This might seem like an obvious point, but the 'O' in JSON seemingly implies that JSON only stores Javascript object which is not true.
  • You can use JSON with a variety of programming languages, not just Javascript applications! As long as there is a JSON parser written in a language, you can use that language to receive JSON data
  • When you stringify a JS object, do not expect to preserve the order of the key-value pairs. As ECMAScript specifies, Javascript objects are un-ordered collections and the JSON format provides no guarantee of storing key-values in a particular order.

Additional resources on JSON:

views