What it does
- Validate: checks that your text is valid JSON, and shows where the first error is.
- Format: indents your JSON with 2 spaces, 4 spaces or tabs.
- Minify: removes extra whitespace to make it smaller.
- Sort keys: puts object keys in order, which makes two files easier to compare.
Common JSON errors
| Mistake | Wrong | Right |
|---|---|---|
| Single quotes | {'a': 1} | {"a": 1} |
| Key without quotes | {a: 1} | {"a": 1} |
| Trailing comma | [1, 2,] | [1, 2] |
| Comment | {"a": 1 // note} | JSON has no comments |
| Missing comma | {"a": 1 "b": 2} | {"a": 1, "b": 2} |
Good to know
- Very large whole numbers can lose precision, because the browser reads JSON numbers as standard floating-point values. If yours have more than 15 digits, keep them as strings.
- If a key appears twice in an object, only the last value is kept.
- Some browsers don’t give an error position, so you may not see a line number.
Is my data private?
Yes. The tool runs in your browser, so nothing you paste is uploaded or stored. It’s still wise not to paste live passwords or secret keys into any website. Need a secure password? Use the password generator.
How to use the JSON formatter and validator
- Paste into “Your JSON”. The box starts with a short sample, so you can see how it works before you paste your own.
- Pick a format. Choose 2 spaces, 4 spaces, Tabs or Minified.
- Pick how keys are ordered. “Keep the order” leaves them as they are. “Sort A to Z” puts the keys of every object in order.
- Read the status. It says “Valid JSON” with the size of the result, or “Not valid yet” with a message about the problem.
- Open the result. It opens on the next page, where you can copy it or download it as formatted.json.
Worked example: the sample, four ways
The sample in the box is one line of 70 characters: an object with a name, a true or false value, a list of two tools and a count. Here is what each format gives:
| Format | Size of the result |
|---|---|
| 2 spaces | 100 characters |
| 4 spaces | 118 characters |
| Tabs | 91 characters |
| Minified | 70 characters |
With 2 spaces the status reads “Valid JSON, 100 characters”. Each key moves onto its own line, and the two tools in the list get a line each. The data is the same in all four versions. RFC 8259 allows spaces, tabs, line feeds and carriage returns around the brackets, colons and commas, and that whitespace has no meaning.[1]
Worked example: finding an error
Paste this four-line object, which has a comma after its last value:
{
"name": "Ann",
"age": 30,
}
The status changes to “Not valid yet”. When your browser reports where the problem is, the tool turns that into a line and a column, here line 4, column 1. That points at the closing brace, the first character the parser didn’t expect. Remove the comma after 30 and the status turns back to valid. MDN confirms that arrays and objects can’t have trailing commas in JSON.[2] Fix the first error, then check again, because one mistake can hide the next.
What valid JSON can hold
JSON has four simple types, strings, numbers, true or false, and null, plus two kinds of container, objects and arrays.[1] An object is an unordered set of name and value pairs, where each name is a string in double quotes. An array is an ordered list of values.[1] That short list explains most validation errors. JavaScript values such as undefined, functions, NaN and Infinity are not valid JSON.[3] Comments and single quotes aren’t allowed either. If you build JSON in code, let the language write it for you rather than joining strings by hand. When you send JSON between systems, RFC 8259 says it must be encoded as UTF-8.[1]
What the formatter can change
The tool reads your JSON into the browser and writes it out again. The meaning stays the same, but a few details can look different:
- Numbers are rewritten. 1.50 becomes 1.5 and 1e3 becomes 1000.
- Escapes are written out. A code such as \u00e9 becomes the letter é.
- Number-like keys move first. Keys such as "2" and "10" come before other keys, in number order, even with “Keep the order”. MDN notes that the output follows the same key order as Object.keys().[3]
- Repeated keys collapse. RFC 8259 says names in an object should be unique, and many programs keep only the last value of a repeated name.[1] This tool does that too.
Very long numbers
JSON itself has no size limit on numbers, but RFC 8259 says whole numbers between −(2^53)+1 and (2^53)−1 are the ones all programs agree on exactly.[1] In the browser the top of that range is 9,007,199,254,740,991.[4] A bigger ID changes when the tool reads it. For example, 12345678901234567890 comes out as 12345678901234567000. If your data has IDs like that, ask for them as strings in quotes, which the formatter leaves untouched.
Sorting keys from A to Z
Sorting puts the keys of every object in order, including objects inside other objects. Lists keep their order, because the order of items in an array matters. Sorting follows character codes, so capital letters come before small ones: Name, age, city, zip. Sorted output is handy when you compare two versions of a file. To see the differences side by side, use the JSON compare tool, or turn a list of records into a spreadsheet with the JSON to CSV converter.
What next
Use this often? Add JSON Formatt to your Home screen.
Frequently asked questions
How do I validate JSON?
Paste it in the box. If it’s valid, you’ll see it formatted. If it isn’t, you’ll see an error, with the line and column where your browser provides them.
Why is my JSON invalid?
The most common causes are single quotes, keys without quotes, trailing commas, comments and missing commas.
Is my data sent to a server?
No. Everything runs in your browser, and nothing you paste is uploaded.
What’s the difference between formatting and minifying?
Formatting adds indents and line breaks so it’s easy to read. Minifying removes them so the file is smaller. The data stays the same.
Why did a long ID number change after formatting?
The browser reads JSON numbers as standard floating-point values, which hold whole numbers exactly only up to 9,007,199,254,740,991. Larger IDs are rounded. Keep them as strings in quotes and they stay exact.
Does sorting keys change my data?
No. Only the order of keys inside objects changes, and JSON objects are unordered by definition. Lists keep their order, and every value stays the same.
Sources
Was this tool helpful?
What went wrong?
We only receive the reason you pick, never what you typed into the tool.
Thanks for your feedback.