For a while I’ve considered JSON to be the same as an object literal in JavaScript.
How wrong I’ve been.
JSON doesn’t support half of this stuff. The JSON format has been developed specifically for data exchange and supports only a subset of what an object literal does.
First of all, property names must be qualified by a double-quote. Single-quotes are not valid. That one had me confused for while as I tried to validate my code.
Secondly, values can only be one of the following: null, string, number, boolean, array, or another JSON object. Functions are definitely not gonna fly.
Generally you’ll be using some other library to generate JSON based on your objects (that’s what kept me so unelightened for so long).
However, for when you need to cut it by hand, there’s a nice little tool at jsonlint.com which you can use to validate your objects.


Newtonsoft has a great opensource library for serialising/deserialising, and creating JSON objects.