How to use the JSON formatter
- Paste JSON into the Input box, or click Load sample to try it.
- Click Format to pretty-print it with 2 spaces, 4 spaces, or tabs. Press Ctrl+Enter (Cmd+Enter on a Mac) as a shortcut.
- Click Minify to remove every unnecessary space and line break, which is useful before storing JSON in a database column or sending it in a request.
- Turn on Sort keys to order object keys alphabetically. Sorted output makes two JSON documents much easier to compare in the Diff Checker.
If the input is not valid JSON, the tool shows the parser's error message together with the line and column where parsing stopped, plus a hint for the most common causes.
What "valid JSON" means
JSON is stricter than the JavaScript object syntax it was based on. A document is valid only when:
- Every key is a string in double quotes:
{"id": 1}, not{id: 1}or{'id': 1}. - Strings use double quotes and escape special characters, such as
\"for a quote and\nfor a line break. - Values are one of: string, number,
true,false,null, an object, or an array.undefined,NaN, andInfinityare not allowed. - There is no comma after the last item in an object or array.
- There are no comments.
//and/* */are not part of JSON.
Example
This input fails because of a single-quoted string and a trailing comma:
{'name': 'Ada', "skills": ["math", "engines",],}
The corrected version, formatted with two spaces:
{
"name": "Ada",
"skills": [
"math",
"engines"
]
}
Common problems and how to fix them
- Unexpected token at position 0. The text probably is not JSON at all. Check for an HTML error page, a BOM character, or a leading
)]}'security prefix that some APIs add. - Unexpected end of input. A closing
}or]is missing, often because the text was cut off when copying from a log. - Bad control character in string. A raw tab or line break appears inside a string. Replace it with
\tor\n. - Large numbers change. JavaScript stores numbers as 64-bit floats, so integers above 9,007,199,254,740,991 lose precision when parsed. If you work with large IDs, keep them as strings.
Frequently asked questions
Is my JSON sent to a server?
No. Formatting and validation use your browser's built-in JSON.parse and JSON.stringify. Nothing you paste is uploaded to QuickToolsBox.
Does formatting change my data?
Formatting only changes whitespace. Sorting keys changes the order of keys inside objects, which does not change the meaning of JSON, but array order is always kept. If an object contains the same key twice, only the last value is kept, because that is how the browser's JSON.parse handles duplicates.
Can it handle JSON Lines or comments?
Not directly. JSON Lines (one JSON value per line) and JSON with comments (JSONC) are separate formats. Format each line individually, or remove the comments first.