JSON (JavaScript Object Notation) is a lightweight text format for storing and exchanging data. Introduced by Douglas Crockford in the early 2000s and formalised as RFC 8259, it has become the dominant data interchange format for APIs, configuration files, and web applications worldwide.
JSON is language-independent โ it can be parsed in Python, Java, Ruby, Go, PHP, Swift, or any other mainstream language. Its simplicity and human-readability made it replace XML in most web API contexts over the past 15 years.
| Type | Example | Notes |
|---|---|---|
| String | "hello" | Must use double quotes โ never single quotes |
| Number | 42, 3.14, -7 | No distinction between integers and floats |
| Boolean | true, false | Lowercase only โ True is invalid |
| Null | null | Lowercase only โ NULL is invalid |
| Array | [1, "two", true] | Ordered list of any JSON values |
| Object | {"key": "value"} | Unordered key-value pairs; keys must be strings |
The most frequent JSON error. JSON does not allow a comma after the last item in an object or array:
JSON requires double quotes for both keys and string values. Single quotes are not valid JSON:
Standard JSON does not support comments. // comment or /* comment */ will cause a parse error. If you need comments in config files, consider JSONC or JSON5 (which require specific parsers), or move to YAML/TOML for configuration.
JSON has no concept of undefined, functions, dates (as objects), or NaN/Infinity. These JavaScript-specific values cannot be serialised to JSON.
Pretty-printed JSON uses indentation (typically 2 or 4 spaces) and newlines for human readability โ ideal for config files, debugging, and version control.
Minified JSON removes all unnecessary whitespace to reduce file size โ ideal for API responses and production builds where bandwidth matters.
In JavaScript: JSON.stringify(data, null, 2) pretty-prints with 2-space indentation. JSON.stringify(data) minifies.
A 10KB pretty-printed JSON file typically minifies to 6โ7KB โ a 30โ40% reduction. For large payloads delivered over mobile connections, this matters.
JSON validators check that your text conforms to the JSON specification and report the exact location of any errors. You should validate JSON whenever you:
JSON is a text format โ it is always a string. JavaScript objects are in-memory data structures. Key differences: JSON requires double quotes around all keys and string values; JS objects allow single quotes and unquoted keys. JSON does not support undefined, functions, Date objects, or comments. JSON.parse() converts a JSON string to a JS object; JSON.stringify() converts a JS object to a JSON string.
No โ standard JSON (RFC 8259) explicitly does not support comments. This was a deliberate design decision by Douglas Crockford to keep the format simple and interoperable. JSON5 and JSONC are unofficial supersets that add comment support, but they require custom parsers and are not universally supported. For config files requiring comments, consider YAML or TOML instead.
The most common causes are: (1) trailing commas after the last element in an array or object, (2) single quotes instead of double quotes around keys or strings, (3) unquoted keys, (4) control characters (tab, newline) embedded literally inside strings instead of escaped as \t or \n, and (5) undefined values (which JSON has no equivalent for). Paste into a JSON formatter to immediately identify the line and character position of the error.
Pretty-printed JSON uses indentation and newlines for readability โ ideal for config files, logs, and debugging. Minified JSON removes all whitespace to reduce file size โ typically 30โ40% smaller. For APIs, minified is preferred for performance. Use JSON.stringify(data, null, 2) in JavaScript or json.dumps(data, indent=2) in Python for pretty output; omit the indent argument for minified output.