Format Bench › JSON Formatter
JSON Formatter and Beautifier
Paste JSON and press Format. Valid input is re-indented; invalid input reports the exact line and column where parsing failed, which is the part most formatters leave out.
● Runs locally. What you paste never leaves this page.
What "valid JSON" actually means
JSON is a far smaller language than most people assume, and nearly every "invalid JSON" error comes from using a JavaScript habit that JSON does not share. The specification (RFC 8259) allows exactly six value types: object, array, string, number, boolean and null. Everything else is a syntax error.
The rules that catch people most often:
- Keys must be double-quoted strings.
{name: "ada"}is valid JavaScript and invalid JSON. So is{'name': 'ada'}, because single quotes are not string delimiters in JSON. - No trailing commas.
[1, 2, 3,]fails. This is the single most common error in hand-edited configuration files. - No comments. Neither
//nor/* */is permitted. Formats that allow them, such as JSON5 or JSONC, are different languages that merely look similar. - Numbers cannot have leading zeros, a leading plus, or a trailing
decimal point.
01,+1and1.are all rejected.NaNandInfinityare not JSON values either, which regularly surprises people serialising floating point data. - Strings must escape control characters. A literal newline inside a
string is invalid; it has to be written
\n.
Reading the error message
When parsing fails this tool reports a line and column rather than only a character offset. The reported position is where the parser gave up, which is not always where the mistake is. A missing closing brace is usually reported at the very end of the document, because that is the first point at which the parser can prove something is wrong. When the reported position looks innocent, check for an unclosed bracket, brace or quote earlier in the file.
Indentation, sorting and stable diffs
Two-space indentation is the common default and is what most linters expect. Four spaces is easier to scan in deeply nested documents. Tabs matter if the file will be read in an editor where users set their own tab width.
The sort keys option rewrites every object with its keys in lexicographic order, recursively. This is worth knowing about because JSON object key order is not semantically meaningful but is preserved by most serialisers, so two documents that are logically identical can produce a noisy diff purely because their keys were emitted in different orders. Sorting both sides first collapses that noise. If you are comparing two documents rather than normalising one, the JSON diff tool compares structure directly and ignores key order for you.
Large files
Formatting happens in your browser, so the practical ceiling is your own memory rather than an upload limit. Documents in the low tens of megabytes format without trouble on a normal machine. Beyond that, the browser has to hold the source text, the parsed object graph and the formatted output at once, and a streaming parser run locally is the better tool.
Because nothing is uploaded, this is also usable on documents you are not allowed to paste into a hosted service: API responses containing customer records, tokens, or anything else covered by a data processing agreement.
Questions
Is my JSON uploaded to a server?
No. Parsing and formatting run in JavaScript on your own machine. There is no upload step and no server-side processing, so pasted data never leaves the browser tab. You can confirm this by opening your browser's network panel and formatting a document: no request is made.
Why does my file fail with a trailing comma?
JSON does not allow a comma after the final element of an array or object, even though JavaScript does. Remove the comma before the closing bracket or brace. This is the most common single cause of parse failures in hand-edited files.
Can I use comments in JSON?
Not in standard JSON. Neither double-slash nor slash-star comments are valid. If you need comments in a configuration file, use JSON5, JSONC or YAML, all of which are different formats that permit them, and convert to JSON at build time.
What does the sort keys option change?
It rewrites every object so its keys appear in alphabetical order, recursively through the whole document. Key order carries no meaning in JSON, so this is safe, and it makes two documents comparable when their keys were serialised in different orders.
How large a file can it handle?
There is no imposed limit. The constraint is your browser's memory, since the source text, the parsed object and the output all have to be held at once. Tens of megabytes is comfortable on a typical machine.