Code Tools
JSON Formatter & Validator
Paste or type any JSON to validate, pretty-print or minify it instantly. All parsing happens locally in your browser. No data is uploaded or sent anywhere.
Input
Output
Output will appear hereHow it works
JSON is a text format defined by RFC 8259, and its grammar is deliberately small. A JSON value is exactly one of six things: an object, an array, a string, a number, the literal true or false, or null. Objects map string keys to values, arrays are ordered lists, and any amount of whitespace between tokens is insignificant. The same document fixes how strings and numbers are written. Strings use double quotes with escape sequences such as \n and \uXXXX, and numbers have no leading zeros but may carry an optional exponent.
This tool is a thin wrapper around that standard. Every check runs in your browser.
Every input is handed to JSON.parse, the parser built into the browser’s JavaScript engine. JSON.parse is deliberately strict, and that strictness is what makes validation useful. It rejects trailing commas, single quotes, unquoted property names, and comments, all of which plain JavaScript object literals tolerate. It requires strings to be enclosed in double quotes and demands that numbers follow the grammar above, so 01 and .5 are invalid while 0.5 and 1e3 are valid. When a rule is broken the parser throws a SyntaxError, which this tool reads to report the exact line and column of the fault.
On success the value is re-serialized with JSON.stringify, so the output is always rebuilt as clean, valid JSON.
Pretty-print mode passes a null replacer plus an indentation argument of two or four spaces, which JSON.stringify uses to lay out nested objects and array elements line by line. Minify mode omits the indentation, so every space, tab, and newline disappears while field order and values are preserved exactly. Because the output is rebuilt from the parsed value rather than from your raw text, the result is normalized JSON with consistent spacing, ready to commit to source control or paste into an API client. Larger indentation values are possible too, but these are the two conventions most teams adopt.
One caveat applies at any size. Parsing is synchronous, so a very large document can briefly block the tab.
Use cases
Inspect API responses without leaving the browser. Paste the body of a curl call, a Postman response, or the payload captured in the Network panel, and the validator confirms the shape while pretty-printing makes nested objects readable. Field order, indentation, and value types become visible at a glance, which is the fastest way to spot a response that does not match the schema you expected, and it works equally well on payloads from unfamiliar services and generated client libraries. It also cleans up minified bundles, where production JavaScript often embeds JSON as one dense line.
Validate config files, CI variables, or seed data before you deploy.
Reformatting turns that dense line into a structured document you can diff, annotate, and reason about. The same normalization keeps JSON in source control stable, so whitespace changes no longer pollute pull requests and reviewers see only the changes that matter. Because nothing leaves the browser, this is also a safe place to reformat tokens and payloads you would rather not paste into a remote service, and it doubles as a teaching aid for newcomers who want to see which patterns are valid JSON and which are conveniences only JavaScript accepts.
Troubleshooting
If validation fails, these causes cover most inputs.
- “Unexpected token”: look for single quotes, unquoted keys, or a trailing comma.
- “Unexpected end of JSON input”: usually a missing closing brace or bracket.
- “Unexpected token” at position 0: the file may carry a UTF-8 byte order mark. Re-save without the BOM first.
- Duplicate keys collapse silently:
JSON.parsekeeps only the last occurrence. - Large inputs freeze: parsing is synchronous, so multi-megabyte documents may stall the tab.
- Precision loss: numbers are IEEE 754 doubles, so integers beyond 253 lose precision.
- Literal newlines in strings: line breaks must be escaped as
\n, not written as real newlines.
FAQ
Is my JSON data uploaded or stored anywhere?
No. Everything runs locally in your browser. Nothing you paste is sent to a server or saved.
What is the difference between 2-space and 4-space indentation?
It is purely cosmetic. Both outputs are valid, equivalent JSON that differ only in visual alignment.
Why does my JSON fail with "Unexpected token"?
JSON is stricter than JavaScript object literals. Single quotes, trailing commas, and unquoted keys are invalid, so use double quotes and remove trailing commas.
Can I format very large JSON files?
Files up to a few hundred kilobytes format instantly. Multi-megabyte inputs may briefly block the tab because JSON.parse is synchronous, so split large documents first.
Does minifying change my data?
No. Minify only removes whitespace and formatting. The parsed value and its field order are preserved exactly.
Does this tool accept comments or unquoted property names?
No. Comments, single quotes, and unquoted keys are not part of the JSON standard, so the validator rejects them. Convert such files to strict JSON first.
Why does a large number come back with fewer digits?
JSON numbers are IEEE 754 doubles. Integers beyond 2^53 are not exactly representable, so keep large values as strings.
The JSON standard and parser references behind this tool
- RFC 8259, the JSON data interchange format. Defines the JSON grammar, the six value types, and the number and string rules this validator enforces.
- MDN: JSON.parse(). The reference for the exact parser used here, covering its strict syntax rules and the SyntaxError it throws on invalid input.
- MDN: The JSON namespace. Documents JSON.stringify and its indentation argument, which power the pretty-print and minify modes here.
- ECMAScript Language Specification. The language standard where JSON.parse and JSON.stringify are formally defined, confirming the behavior is native and standards-based.