JSON Formatter and Validator
Paste JSON to pretty-print it, minify it or find out exactly why it is invalid. Errors come with a line, a column and a plain-English fix, and your data stays in your browser.
JSON input
Formatted JSON
Your formatted JSON will appear here. Paste JSON on the left or press Load sample.
Options
How to format and validate JSON
- Add your JSON. Paste it, drop a .json file onto the page, or press Load sample.
- Read the verdict. Valid JSON is pretty-printed straight away. If it is invalid, you get the line and column, a few lines of context with a caret under the problem, and a suggestion for the fix.
- Copy or download. Choose an indent of 2 or 4 spaces, tabs or a minified single line, then copy the result or save it as a .json file.
There is no format button. The result updates as you type or change an option. The Tree tab lets you fold and unfold objects and arrays when the document is large.
Before
{"id":7,"tags":["a","b"],"owner":{"name":"Ava","active":true}}
After
{
"id": 7,
"tags": [
"a",
"b"
],
"owner": {
"name": "Ava",
"active": true
}
}
Common JSON errors and how to fix them
JSON looks like a JavaScript object, but its rules are stricter. Almost every “invalid JSON” message comes from one of the mistakes below, usually after text was copied from code, a log or a document.
| Mistake | Invalid | Valid |
|---|---|---|
| Trailing comma | {"a": 1, "b": 2,} | {"a": 1, "b": 2} |
| Single quotes | {'name': 'Ava'} | {"name": "Ava"} |
| Unquoted key | {name: "Ava"} | {"name": "Ava"} |
| Comment | {"a": 1 // note} | {"a": 1} |
| Missing comma | {"a": 1 "b": 2} | {"a": 1, "b": 2} |
| Python values | {"ok": True, "x": None} | {"ok": true, "x": null} |
| NaN or Infinity | {"n": NaN} | {"n": null} |
| Leading zero | {"zip": 00501} | {"zip": "00501"} |
| Line break in a string | A string that continues on the next line | "line one\nline two" |
| Curly quotes | {“a”: 1} | {"a": 1} |
The error message names the mistake it found. Where a problem has a fix this page can make safely, an Auto-fix button appears with a count of what it would change, such as “2 trailing commas, 3 single-quoted strings”.
What auto-fix changes, and what it never touches
Auto-fix only repairs mistakes where the intent is clear, and it lists every kind of repair it made so you can check the result.
- Repairs it makes
- Removes comments and trailing commas, turns single and curly quotes into double quotes, quotes bare keys, adds a missing comma between items, writes
True,FalseandNonein JSON form, and replacesNaN,undefinedandInfinitywith null. - Repairs it will not guess
- Text that was cut off, brackets that do not match, unquoted text values and numbers with leading zeros. These still show an error, because any guess could change your data.
Formatting that does not change your data
Many formatters parse the JSON and write it back, and that round trip can quietly alter it. JavaScript stores every number as a 64-bit float, so an ID such as 12345678901234567890 comes back as 12345678901234567000, and 1.10 becomes 1.1.
This formatter does not convert numbers or strings at all. It reads the text, checks the structure and rewrites only the whitespace, so long IDs, trailing zeros, exponent notation and escape sequences such as é come out exactly as they went in.
Sorting keys is the one option that reorders content. It sorts object keys alphabetically at every level and leaves arrays in their original order, because the order of array items usually carries meaning.
What this formatter does
- Private by design
- Validation and formatting run in your browser with JavaScript. Your JSON is not sent to a server, so it is safe to use with API responses, tokens in test data and customer records.
- Follows the standard
- Strict mode checks your text against RFC 8259, the current JSON specification, so a document that passes here will pass in any compliant parser.
- Exact error positions
- Each error reports the line and column, shows the surrounding lines with a caret, and can select the character in the input box. A string or bracket that is never closed points to where it was opened.
- Duplicate key warning
- The specification says names in an object should be unique, and most parsers keep only the last one. The formatter tells you when a key appears twice so the lost value does not surprise you.
- Large files
- Files up to 100 MB can be loaded. In our tests a 15 MB document with 200,000 records was validated and formatted in about a second and a half. The tree view is turned off for very large documents, and the text view shows the first 1 MB.
- Works with the other tools
- Getting an “Unexpected token” error in code? Read what it means and how to fix it. Once your JSON is valid, send it on to the JSON to CSV converter or the JSON to Excel converter.
Frequently asked questions
How do I format JSON online?
Paste your JSON into the input box, or drop a .json file onto the page. It is checked and pretty-printed straight away. Pick an indent of 2 spaces, 4 spaces or tabs, then press Copy or Download. There is no format button, and the result updates as you type.
Is my JSON uploaded to a server?
No. The JSON is validated and formatted by JavaScript in your browser tab, and nothing is sent anywhere. That makes it safe for API responses and internal data. Closing the tab discards everything.
Why does it say my JSON is invalid?
JSON is stricter than a JavaScript object. The usual causes are a trailing comma, single quotes instead of double quotes, keys without quotes, comments, a missing comma, or Python values such as True and None. The message names the mistake, gives the line and column, and shows the surrounding lines with a caret under the problem.
What does the Auto-fix button do?
When the only problems are ones with a clear intent, such as trailing commas, single or curly quotes, comments, unquoted keys, missing commas between items, and True, False, None, NaN or undefined, it repairs them and tells you how many of each it changed. Review the result before you use it. Cut-off text and mismatched brackets are not guessed, and still show an error.
What is the difference between formatting, minifying and validating?
Validating checks that the text is legal JSON. Formatting, also called pretty-printing, adds line breaks and indentation so people can read it. Minifying removes all optional whitespace to make the file smaller. All three happen here: pick Minified under Layout to compress, and any valid input is also validated.
Will formatting change my numbers or IDs?
No. Some tools parse JSON into JavaScript values and write it back, which rounds numbers over 15 or 16 digits and drops trailing zeros, so 1.10 becomes 1.1. This formatter keeps the original text of every number and string and only changes whitespace.
Does sorting keys change the meaning of my JSON?
The order of keys in an object has no meaning to a JSON parser, so sorting them is safe and makes two documents easier to compare. The order of items in an array can matter, so arrays are never reordered.
Why am I warned about duplicate keys?
The JSON specification says the names inside an object should be unique. Documents with a repeated name are still accepted, but different parsers disagree on the result, and most keep only the last value. The warning tells you a value may be silently lost.
Can it handle JSON Lines or several JSON objects in a row?
A JSON document holds a single value, so two objects one after another are reported as an error at the point where the second begins. To work with that data, wrap the objects in square brackets and separate them with commas, or use the JSON to CSV converter, which reads JSON Lines.
How large a JSON file can I format?
Files up to 100 MB can be loaded. In our tests a 15 MB file with 200,000 records took about a second and a half. The limit in practice is your device's memory. For very large files the tree view is turned off and the text view shows the first 1 MB, while Copy and Download still include everything.