JSON Formatter
Paste JSON to pretty print it with 2 spaces, 4 spaces or a tab, or to minify it. If the JSON is invalid, the error shows its line and column.
How to use
- Paste your JSON into the input box.
- Choose Format and pick 2 spaces, 4 spaces or a tab. Choose Minify to remove all extra whitespace, or Validate to only check it. Tick Sort keys to order object keys A to Z.
- If the JSON is invalid, the message shows the line and column, and the cursor jumps to that spot when you press the button. Fix it and the result updates as you type.
- Press Copy to copy the result.
How it works
The tool parses your text with the JSON parser built into your browser, then writes it back with the indent you chose. If parsing fails, it reads the character position from the browser's error message and converts it to a line and column. Chrome, Edge, Firefox and Safari word these messages differently, so for a few errors Safari gives no position and only the message is shown.
Sorting keys orders them by character code, at every level. Arrays keep their order. Because JavaScript objects always list whole-number keys such as "1" and "2" first, those keys stay at the top in numeric order.
The output is re-serialized, so it can differ from the input in small ways: duplicate keys keep only the last value, escapes like \u00e9 become the plain character, and numbers are printed in their shortest form (1.0 becomes 1).
Common JSON errors
| Mistake | Example | Fix |
|---|---|---|
| Trailing comma | {"a": 1,} | Remove the last comma |
| Single quotes | {'a': 1} | Use double quotes |
| Unquoted key | {a: 1} | Write "a" |
| Comment | {"a": 1} // note | Remove it, JSON has no comments |
| Missing comma | {"a": 1 "b": 2} | Add a comma between pairs |
FAQ
Is my JSON uploaded anywhere?
No. Parsing and formatting happen in your browser and your text is never sent to a server.
Why is my JSON invalid when it looks fine?
The usual causes are a trailing comma, single quotes instead of double quotes, unquoted keys, comments, or a missing comma between items. JSON is stricter than a JavaScript object literal.
What is the difference between format and minify?
Format adds line breaks and indentation so people can read it. Minify removes all whitespace outside strings to make the text as short as possible, which is useful for requests and storage.
Does sorting keys change the meaning of the data?
No. Order of keys in a JSON object has no meaning to most programs. Arrays are never reordered.
Why does the error position look off by one?
Parsers report where they gave up, which is often just after the real mistake, such as the character after a missing comma. Look at the line before the marked spot too.