Common JSON errors
- Single quotes: strings and keys must use double quotes.
{'a': 1}works in JavaScript but not in JSON. - Trailing commas:
[1, 2, 3,]is invalid; remove the comma after the last item. - Unquoted keys:
{name: "a"}must be{"name": "a"}. - Comments: JSON doesn't allow // or /* */ comments.
- undefined and NaN: JSON values can only be strings, numbers, true, false, null, arrays and objects.
When to pretty print or minify
API responses and logs often arrive as one long line; indenting them makes the structure readable. Minified JSON drops every unnecessary space, which keeps payloads and stored files small. Sorting keys removes noise when you diff two JSON documents whose keys are in a different order.
FAQ
Why did a very large number change?
JavaScript can't represent integers above 253 (about 9 quadrillion) exactly, so long numeric IDs may lose their last digits after formatting. Send such values as strings in your data.
Is my JSON sent anywhere?
No. Validation and formatting happen in your browser, so it's safe to use with data that contains API keys or personal information.