JSON Formatter & Validator
Paste JSON and pretty-print it with 2, 4 or 8 spaces, squeeze it onto one line, or just check that it parses. Valid JSON comes back colour-coded with the size before and after; invalid JSON comes back with your browser's own error message. Free, no sign-up, and nothing you paste leaves your browser.
0 lines · 0 bytes
How to Use the JSON Formatter
- 1. Paste your JSON. Anything from a single value to a large API response. The box counts lines and bytes as you type.
- 2. Pick an indent. Choose 2, 4 or 8 spaces. The setting only affects Format.
- 3. Choose an action. Format pretty-prints, Minify removes every optional space and line break, and Validate only checks the syntax and shows a green or red verdict without producing output.
- 4. Read the result. Valid JSON is shown colour-coded (keys purple, strings green, numbers blue, true and false orange, null red) with the input size, output size and percentage change. Invalid JSON shows the parser's message instead. Copy Output copies what you see.
What Counts as Valid JSON
The tool hands your text to the JavaScript engine's strict JSON parser, so it accepts what the format's standard, RFC 8259 (the same grammar as ECMA-404), accepts — and nothing more. That is stricter than a JavaScript object literal, which is why code that works in a script often fails here. The usual culprits:
| Mistake | Example | Fix |
|---|---|---|
| Trailing comma | {"a": 1,} | Delete the last comma. |
| Single quotes | {'a': 1} | Use double quotes for every key and string. |
| Unquoted key | {a: 1} | Quote it: {"a": 1}. |
| Comment | // note or /* note */ | JSON has no comments; delete them. |
| Leading zero or plus sign | 007, +5 | Write 7 and 5. |
| NaN, Infinity or undefined | {"x": NaN} | None exist in JSON; use null or a string. |
| Raw line break in a string | a newline inside quotes | Write it as the two characters \n. |
| Missing comma | {"a": 1 "b": 2} | Separate members with commas. |
A lone 42, "text" or null is valid too: since RFC 7159 a JSON text can be any value, not only an object or array. Capitalised True or NULL are not — the three literals are lowercase.
What Formatting Changes
This tool parses your JSON and writes it back out, so the result is the same data in a new layout, not a character-for-character copy of your text. Four things can differ, and the first two matter if you format JSON that feeds another system:
- Large integers lose precision. JavaScript numbers are 64-bit floats, so integers above 9,007,199,254,740,991 (253 − 1) are rounded.
9007199254740993comes back as9007199254740992. If your IDs are that big, keep them as strings. - Duplicate keys collapse. RFC 8259 says names should be unique but does not forbid repeats; this tool keeps the last value and drops the earlier ones.
- Integer-like keys move first. In JavaScript, keys such as
"1"and"2"are listed before other keys in ascending order, so{"b":1,"2":1,"1":1}is written back as{"1":1,"2":1,"b":1}. Other keys keep your order. - Numbers and escapes are rewritten.
1.50becomes1.5,1e2becomes100, and\u00e9becomesé.
Worked Example
Take this 119-byte input, which includes a large ID, a trailing zero, an exponent and an escape:
Input
{"title":"APA Manual","year":2020,"tags":["style","7th"],"id":9007199254740993,"price":1.50,"x":1e2,"name":"caf\u00e9"}
Format with 2 spaces writes 156 bytes (+31%), one member per line, with "id": 9007199254740992, "price": 1.5, "x": 100 and "name": "café". Minify writes 114 bytes (-4%) on a single line, with the same changes. Nothing else about the data differs. Sizes are UTF-8 bytes, so the é counts as two.
Which Tool Do You Need?
This page is for JSON itself. If your data is in another format, a sibling does the job: CSV to JSON for spreadsheets, the planned YAML to JSON and XML to JSON converters, XML Formatter for XML documents and HTML Formatter for markup.
Frequently Asked Questions
- What does a JSON formatter do?
- It parses JSON and writes it back with consistent indentation and one member per line, so a minified API response becomes readable. Because it has to parse first, it doubles as a validator: text that isn't valid JSON produces an error instead of output.
- Why does my JSON say it is invalid?
- Usually one of the mistakes in the table above: a trailing comma, single quotes, an unquoted key, a comment or a missing comma. The message comes from your browser's own JSON parser, so its wording differs between Chrome, Firefox and Safari, and it may or may not give a position; look for the problem at or just before the point it names.
- Can I format JSON with comments, JSON5 or JSONC?
- No. Comments, trailing commas and single quotes are not part of JSON, and this tool uses a strict parser. Remove them first, or convert the file to plain JSON in your editor.
- What is the difference between Format, Minify and Validate only?
- Format adds indentation and line breaks, Minify removes all optional whitespace to give the smallest text, and Validate only checks the syntax and shows a verdict with no output. All three use the same parser, so a document that passes one passes all of them.
- Why did a number in my JSON change?
- The tool reads numbers as JavaScript floats and prints them back in JavaScript's shortest form. That turns
1.50into1.5and1e2into100, and it rounds integers larger than 253 − 1. Store very large identifiers as strings if they must survive exactly. - Is my JSON uploaded anywhere?
- No. Parsing, formatting and highlighting all run in your browser, and the text you paste is not sent to CitationEasy or anyone else. Clear the box when you finish on a shared computer.
- Can I sort the keys or use tabs for indentation?
- Not here. The indent choices are 2, 4 or 8 spaces, and keys stay in the order your input gave them, apart from integer-like keys moving first as described above.