Formatting and validating JSON step by step
- Paste your JSON into the JSON input field, drop a .json file onto it, or use "Load from file" (files up to 2 MB). The buttons under "Try an example" load a sample.
- The output refreshes while you type. The Format JSON button runs the same check on demand and moves the cursor back into the input if the JSON is invalid.
- With no option ticked you get two-space indentation. Tick Minify output to remove indentation and line breaks (spaces inside strings stay), or tick "Sort object keys recursively" to reorder the keys of every object.
- Read the result under Formatted JSON. The "Lines" and "Characters" counters describe the output, not your input. Below it, the "Data tree" shows each object and array as a collapsible row with its item count, and the first two levels start expanded.
- Click Copy result to put the output on your clipboard, or "Download result" to save it as a file. "Clear" empties the input and also unticks both options.
Examples: beautify, sort, minify
The built-in "Nested object" example, pretty-printed:
{"user":{"name":"Alice","roles":["admin","editor"]}}
becomes 9 lines and 91 characters:
{
"user": {
"name": "Alice",
"roles": [
"admin",
"editor"
]
}
}
With key sorting on, keys are reordered at every level, but array items stay in their original order:
{"z":{"b":2,"a":1},"a":[{"d":4,"c":3}]}
{
"a": [
{
"c": 3,
"d": 4
}
],
"z": {
"a": 1,
"b": 2
}
}
Keys are sorted in your browser's alphabetical order, so lowercase and uppercase letters are not split into separate groups (a, b, B). The exact position of accented letters follows your browser's language settings. Keys made only of digits (no leading zero or minus sign) come first, in numeric order (9 before 10); keys such as 01 or -1 are sorted as text. The order can therefore differ from jq -S or Python's sort_keys, which sort by character code.
Minifying goes the other way. An indented document such as { "z": 1, "a": [3, 1] } spread over four lines becomes {"z":1,"a":[3,1]}: one line, 17 characters.
What the validator rejects
The tool accepts strict JSON as defined in RFC 8259 and nothing looser. Many "why is my JSON invalid" questions come from syntax that JavaScript or config files allow but JSON does not:
| Input | Why it fails |
|---|---|
{'a':1} |
Keys and strings must use double quotes |
{"a": 1,} |
No trailing comma after the last item |
{"a":1} // note |
Comments are not part of JSON |
{a:1} |
Keys must be quoted strings |
When a document fails, the output stays empty and a red message appears under the input. In Chrome, Edge and other Chromium browsers the message usually also gives a line and column. For example, the trailing comma in a three-line object {, "a": 1,, } is reported at line 3, column 1, where the parser expected another key. Use the line numbers in the input's left gutter to find the spot.
A valid document can still come out different from what you pasted, because the tool re-serializes the parsed value instead of only re-indenting your text:
- Numeric keys: keys made of digits only (such as
"1"or"42") are moved to the start of their object, in numeric order, even without sorting.{"b":1,"1":2,"a":3}becomes"1","b","a". - Large integers: numbers are read as 64-bit floating point, so integers longer than about 15–16 digits are rounded.
{"id":12345678901234567890}becomes"id": 12345678901234567000. If long IDs must stay exact, keep them as strings. - Duplicate keys:
{"a":1,"a":2}is accepted without an error and becomes"a": 2. Only the last value is kept. - Notation:
1.10becomes1.1, and escapes such as\u00e9are written out asé.
A bare value such as "just a string" or 42 is valid JSON and is returned unchanged.
Typical uses
- Reading an API response: paste a minified body from your browser's network tab or from curl, then collapse the parts you don't need in the tree.
- Comparing two payloads: format both with key sorting on, then paste them into Text Diff / Compare. With the keys in the same order, the diff shows only real changes in values.
- Preparing config or fixtures: minify JSON before putting it in an environment variable or a one-line test fixture, or beautify it before committing so code reviews are readable.
- Checking hand-edited files: load a
package.jsonor a translation file to find the stray comma before your build fails.
Limits and when to use another tool
Everything runs in your browser, so the practical limit is your device's memory. Typed or pasted text is capped at 1,000,000 characters, and files loaded from disk can be up to 2 MB. The text output always contains the full document, but the Data tree stops after 1,000 nodes and shows a notice.
If you need rows and columns instead of a nested document, convert an array of objects with JSON to CSV. If your config is in YAML, or you want to convert between YAML and JSON, use the YAML Formatter & Converter.