Simon Willison’s Weblog

Subscribe

How is JSON different then a JavaScript (programming language) object?

17th January 2012

My answer to How is JSON different then a JavaScript (programming language) object? on Quora

JSON is a carefully selected subset of JavaScript. A JSON object can only consist of dictionaries, strings, numbers (in JavaScript floating point and integers are treated as the same thing), lists, booleans and null. The spec on JSON.org is a good guide: http://json.org/

In terms of formatting, JSON objects must have double quotes around strings (JavaScript allows single quotes) and must have double quotes around dictionary keys (optional in JavaScript for keys that only contain a-zA-Z0-9_).

JSON is also strict about not leaving trailing commas on dictionary and list declarations, whereas most JavaScript engines will let you get away with those.

More recent articles