How to Format and Validate JSON (With Common Errors Explained)
JSON is the format most web services use to send data. It is readable in principle, but real-world responses often arrive as one enormous line. A formatter makes the structure visible; a validator tells you exactly where it is broken.
Formatting (beautifying)
Paste your data into the JSON Formatter & Tree Explorer and it will indent the structure so you can see which values are nested inside which. The tree view lets you collapse parts you do not care about. When you need the opposite, for example to save bytes in a config file, JSON Minifier removes the whitespace.
The most common JSON mistakes
- Trailing comma.
{"a": 1, "b": 2,}is invalid. The last item must not have a comma after it. - Single quotes. JSON requires double quotes around keys and string values.
- Unquoted keys.
{name: "Sam"}works in JavaScript but not in JSON; it must be{"name": "Sam"}. - Comments. JSON has no comment syntax. Remove any
//or/* */. - Special values.
undefined,NaNand functions are not valid JSON values. - Unescaped characters. Quotes and backslashes inside strings must be escaped with a backslash.
Validating
If a formatter reports an error, JSON Validator points to the position of the problem. For stricter rules, such as "this field must be a number and is required", use JSON Schema Validator with a schema describing the shape you expect.
Comparing two JSON documents
When an API response changed and you need to know what, JSON Diff highlights added, removed and modified fields instead of making you compare long lines by eye. To pull one value out of a big structure, try JSONPath Tester.
Converting to other formats
- Spreadsheet people want rows: JSON to CSV or JSON to Excel.
- Configuration files often use YAML: JSON to YAML and back with YAML to JSON.
- Legacy systems may need XML: XML to JSON converts in the other direction.
A note on privacy
API responses can contain tokens, emails or other personal data. Check the badge on the tool page to see whether it runs in your browser, and remove secrets before sharing any data with others.
Frequently asked questions
Is JSON the same as a JavaScript object?
They look alike, but JSON is stricter: keys must be in double quotes, no trailing commas, no comments and no functions or undefined values.
Why does my JSON fail with an error at position 1?
Often the text is not JSON at all, for example an HTML error page returned by a server, or it starts with an invisible character. Check the first characters of the response.
Can JSON contain dates?
Not as a native type. Dates are stored as strings, commonly in ISO 8601 format like 2026-10-20T14:30:00Z, or as timestamps.
What is the difference between formatting and validating?
Formatting changes only the layout to make it readable. Validating checks the rules: whether the structure is legal JSON and, with a schema, whether it has the fields and types you expect.
Key takeaways
- Most errors are trailing commas, single quotes or comments.
- Validate before you format when something looks wrong.
- Remove secrets before sharing data.