JSON Light At A Glance March 31, 2012
OData/WCF Data Services currently supports a JSON format that has a couple of problems. The two thatinspired the design of JSON Light are:
Payload size: the current JSON format is too verbose on the wire thus unnecessarily increasing
the payload size of a response. As a result we now refer to the existing JSON format also as ‘JSONverbose’.
Ease-of-use for JScript/jQuery processors: JSON verbose has a set of wrapper objects (especiallyaround collections) that make the format hard to use in JScript/jQuery since these wrapperswere sprinkled in between the actual data. As a result extracting the actual data (without anycontrol information) as JSON involved stripping out all such wrappers and, for a set of clients,made it harder to access the data than it should be.
Disclaimer: this document represents preliminary thinking about a light-weight JSON format for OData.Not all aspects of this new format have been locked down yet and in particular the names and constantsare likely to change.
JSON Light Design
A few requirements guided the development of the JSON Light format; the most important ones arelisted below as a frame of reference but are not discussed in detail.
The payload size should be minimized while preserving all the information present in the currentATOM and JSON verbose formats.
The response payloads should be easy to consume in pure JScript or jQuery processors.
The format should intrinsically support extensibility for future versions of OData.
The format should support streaming (e.g., for endless feeds) with the assumption that only asingle entry ever fits into memory.
Clients should be able to control the trade-off between payload size on the wire andcomputational requirements on the client.
The system should be fully functional with no out-of-band information in clients.
Feedback from the OData/REST community should continuously influence the format to get thebroadest possible support for JSON Light.The approach we took to accomplish the above is as follows: in order to make the new format easy toprocess by JScript/jQuery clients, we have to continue to use a JSON representation on the wire (asopposed to a binary representation for example). Looking at the current JSON (verbose) payloads, largeparts of the payload are highly stylized (for example, the edit links for all the entries in a feed might onlydiffer in the value of the key property of the entry but otherwise be identical). To minimize the payloadsize, all the stylized pieces in the payload were removed from the actual wire format. Instead,expressions to compute the stylized payload parts were added in annotations to the metadata