How to format, minify or validate JSON
- Paste your JSON into the input box, or click Load example.
- Choose Format or Minify. Format adds line breaks and indentation so you can read it. Minify removes every space and line break that isn't inside a string.
- Pick the indentation (2 spaces, 4 spaces or a tab) and whether to sort keys.
- Read the status bar. Green means the JSON is valid. Otherwise you see the error, the line and column, and the line itself with a
^under the problem. - Copy or download the result.
The tool waits until you pause typing before it checks, so it stays responsive with large files. Everything runs in your browser, which makes it safe for API responses that contain tokens or customer data.
Worked example
This minified input:
{"name":"Asha Rao","skills":["UI","branding"],"rate":{"amount":45,"currency":"USD"}}
formatted with 2 spaces becomes:
{
"name": "Asha Rao",
"skills": [
"UI",
"branding"
],
"rate": {
"amount": 45,
"currency": "USD"
}
}
Formatting and minifying change only the whitespace between values. The data stays the same.
Common JSON errors and how to fix them
| Problem | Invalid | Valid |
|---|---|---|
| Trailing comma | {"a": 1,} | {"a": 1} |
| Single quotes | {'a': 'x'} | {"a": "x"} |
| Key without quotes | {a: 1} | {"a": 1} |
| Missing comma | {"a": 1 "b": 2} | {"a": 1, "b": 2} |
| Comments | {"a": 1} // note | {"a": 1} |
| JavaScript-only values | [NaN, undefined] | [null, null] |
| Leading zero | {"id": 007} | {"id": 7} or {"id": "007"} |
The reported position is where the parser noticed the problem, which is often just after the real mistake. A missing comma, for example, is reported at the start of the next key. Look at the end of the previous line too.
Indentation and sorted keys
Two spaces is the most common style for JSON on the web. Four spaces is the default of Python's json.tool module. Tabs keep files a little smaller and let each reader choose the width in their editor.
Sort keys puts the keys of every object in alphabetical order, at every level. The JSON standard (RFC 8259) treats an object as unordered, so sorting doesn't change the meaning. It makes two versions of a file much easier to compare. Arrays keep their order, because order matters in an array.
Limits to know about
- Very large numbers: browsers store numbers as 64-bit floating point. Integers above 9,007,199,254,740,991 (253 − 1) lose precision, so
12345678901234567890is shown as12345678901234567000. If your IDs are that long, store them as strings. - Duplicate keys: if an object repeats a key, only the last value is kept.
- File size: files of several megabytes are fine. The real limit is your device's memory.
Frequently asked questions
Is my JSON sent to a server?
What does "Unexpected token" mean?
Can JSON have comments?
"_comment".What is the difference between JSON and a JavaScript object?
undefined.How do I minify JSON?
Last updated . How we check our tools.