Free tool
JSON Formatter
Format, minify and validate JSON in your browser, with the line and column of the first syntax error.
How it works
What is the JSON Formatter?
The JSON Formatter is a free tool that formats, minifies and validates JSON in your browser. Paste JSON and it is re-indented with 2 spaces, 4 spaces or tabs, or squeezed onto one line. If the JSON is invalid, it shows the line and column where parsing stopped and a plain description of the problem.
How to use the JSON Formatter
- Paste your JSON into the box, or press Load sample.
- Pick an output style: 2 spaces, 4 spaces, Tab or Minify.
- If the status says Invalid, go to the line and column shown and fix the error.
- Press Copy JSON to take the result.
What is a JSON formatter?
A JSON formatter takes JSON text and rewrites it with consistent indentation and line breaks so a person can read it. The data does not change, only the whitespace between the values.
This one parses your input with the browser's own JSON.parse and writes it back with JSON.stringify, so the output is always strictly valid JSON. Minify does the reverse: it strips every optional space and newline to give the smallest text that means the same thing.
How do I validate JSON and find the error?
Paste it in. If it parses, the status reads Valid JSON. If it does not, the output box shows the line and column where parsing stopped, a short description, and the offending line with a caret under the position.
The position is where the parser gave up, which is at or just after the real mistake. A missing comma on line 4 is usually reported at the first character of line 5, because that is where the parser met something it did not expect.
What are the most common JSON syntax errors?
Four mistakes cover most invalid JSON. A trailing comma after the last item in an object or array. Single quotes where JSON requires double quotes. Property names with no quotes, which JavaScript allows and JSON does not. And comments, which the JSON specification (RFC 8259) has no syntax for.
The tool names the first three directly. Other things JSON forbids include undefined, NaN, numbers with a leading zero such as 01, and raw line breaks inside a string.
Should I minify JSON?
Minify JSON that machines read: API responses, config embedded in a page, and structured data in a script tag. The Input and Output figures show the size of each in bytes, so you can see what the whitespace cost.
Keep formatted JSON for anything a person edits or reviews, such as config files in a repository. If your server compresses responses with gzip or Brotli, the saving from minifying is smaller than the raw byte counts suggest, because repeated whitespace compresses well.
Does formatting change my data?
It changes whitespace and nothing you would call data, with a few edge cases worth knowing because the tool goes through JavaScript's parser. Numbers are rewritten in JavaScript's form, so 1.0 becomes 1 and integers beyond about 16 digits lose precision. If an object repeats the same key, only the last value is kept. Key order is preserved, except that keys that look like whole numbers are moved first.
For schema markup, the JSON-LD Formatter does the same job and also reads script tags. To compare two versions of a file, format both and paste them into the Text Diff Checker.
Questions
- Can JSON have comments?
- No. Standard JSON has no comment syntax, and
JSON.parserejects//and/* */. Formats such as JSON5 and JSONC allow them, but this tool validates strict JSON. - Are trailing commas allowed in JSON?
- No. A comma after the last item of an object or array is a syntax error in JSON, even though JavaScript accepts it. The tool reports it as a trailing comma.
- What indentation should JSON use?
- There is no rule in the specification. Two spaces is the most common convention, four spaces and tabs are also widely used. Match whatever the project already uses.
- Is there a size limit?
- No fixed limit. The work happens in your browser tab, so very large files, in the tens of megabytes, can make the page slow to respond.
- Is the JSON Formatter free?
- Yes, with a free spyc.ai account. It runs in your browser, so nothing you type or paste is sent to a server.
Developer Tools
More in Developer Tools
JSON-LD Formatter
Pretty-print JSON-LD pasted bare or in script tags, list every @type and flag a missing @context.
Format JSON-LDCase Converter
Convert text to upper, lower, title or sentence case, or to camelCase, PascalCase, snake_case and kebab-case.
Convert caseEm Dash Remover
Replace every em dash, and optionally en dashes, with a comma, hyphen or period, and count the changes.
Remove dashesReady when you are
Before your next buyer asks AI about you, ask AI about yourself
One check, four engines, about twenty seconds. We show you the answers before we ask for anything.