Guides / Files and data guides
How to Format and Validate JSON
To format JSON, open JSON Formatter, paste your JSON, choose Format, and pick an indent of 2 spaces, 4 spaces or a tab. To shrink it onto one line, choose Minify. To check it without changing anything, choose Validate. If the JSON is broken, the tool shows the line and column and explains the problem in plain words. It runs in your browser, so the data is not uploaded, and numbers are copied exactly as you wrote them.
How to format JSON, step by step
- Open JSON Formatter. Paste your JSON into the box, or choose or drop a .json file.
- Pick a mode: Format for pretty printing, Minify for the smallest size, or Validate for a check only.
- Choose the Indent: 2 spaces, 4 spaces or tab. Tick Sort keys if you want alphabetical order.
- Read the status line. If the JSON is valid it describes what it found, such as an object with 12 keys. If not, it gives the line, the column and the reason.
- Copy the result or download it as a .json file.
The output updates as you change settings, so you can switch between modes without pasting again.
What each mode does
Format
Format puts each key and each list item on its own line, indented to show the nesting. It is the mode to use when you want to read, review or compare JSON. Text, numbers and the order of keys stay exactly as they were unless you tick Sort keys.
Minify
Minify removes every space and line break that is not inside a string. The status line shows how much smaller the text became. It suits JSON that is sent between programs or pasted into a place where size matters. It is still the same data. Format it again any time you need to read it.
Validate
Validate checks the JSON and shows nothing else. It is quick when you only need to know whether a file will parse. A valid result gives a short summary, and an invalid one gives the exact problem.
Sort keys: when to use it
Sort keys arranges the keys of every object alphabetically, at every level of nesting. That helps when you want to compare two versions of a file, because the same data then appears in the same order. It never reorders the items inside a list, because the order of a list is part of its meaning. Leave it off if the order of keys in your file matters to a person reading it.
The most common JSON errors
JSON is stricter than it looks. These are the mistakes people make most often, along with what the tool tells you and what to do.
Trailing commas
A comma after the last item in an object or list is not allowed. The tool points at the comma and says there is a comma right before the closing brace or bracket. Delete it.
Single quotes
JSON strings and property names must use double quotes. Single quotes, which are fine in many programming languages, are rejected with a message that says so. Replace them with double quotes.
Unquoted keys or text
Every property name needs double quotes, and text values must be quoted too. Only true, false and null can appear without quotes. If you wrote a bare word, the message tells you which one the tool found.
Missing commas or colons
Two properties or items next to each other need a comma between them, and each property name needs a colon after it. The messages say which one was expected, and for commas they also point out that a bracket or brace earlier on may be unclosed.
Missing or extra brackets
If an opening brace or bracket is never closed, the tool reports where it began, so you can find the unclosed one. Extra text after the end of the JSON is reported as well, because a JSON document holds exactly one value.
Comments
JSON does not allow comments, whether they start with two slashes or a slash and an asterisk. Remove them, or keep the commented version as a separate file.
Numbers written the wrong way
Numbers cannot start with a plus sign, cannot have a leading zero followed by more digits, such as 01, and need a digit on each side of a decimal point. A minus sign or exponent must be followed by digits.
Values JSON does not have
NaN, Infinity and undefined are not JSON. Use null, a number or a string instead.
Line breaks and bad escapes inside text
A raw line break inside a string is not allowed. Write it as n. Backslashes also need care: a path such as C:Users must be written with doubled backslashes.
Reading the error message
When something is wrong, the status line starts with the line and column, then explains the problem. Under it, the tool prints the line itself with a caret pointing at the spot. Keep in mind that the position is where the parser noticed the trouble, which is sometimes just after the real mistake. If you see a message about an unexpected character, look at the end of the previous line and at the previous item as well. A missing comma at the end of one line is reported on the next line, for example.
The tool does not repair JSON or guess what you meant. It tells you where the problem is and what it is, and you correct it. That keeps your data from being changed in ways you did not choose.
A worked example
Imagine you copy a small settings object from a chat message and it fails. Paste it into JSON Formatter and the status line says something like line 3, column 12, with a note that property names must use double quotes. The line below shows your text with a caret under the offending word. You change the single quotes to double quotes and the next message appears: there is a comma right before the closing brace. You delete the comma, and now the status line reports a valid object with a number of keys. Switch to Format and the result is neatly indented, ready to read or save. The whole job takes a minute, and each message told you exactly what to change.
This is the usual rhythm. Broken JSON from a chat, an email or a hand-edited file tends to have two or three small faults, and the tool shows them one after another. If the message count feels long, remember that the faults are usually the same kind repeated, for example single quotes throughout. Fix the first occurrence, then use find and replace in your editor for the rest.
Choosing an indent
- 2 spaces is compact and common for web projects and configuration, and it keeps deeply nested data from running off the screen.
- 4 spaces is easier to scan when the nesting is shallow.
- Tab lets each reader choose how wide the indent looks in their editor.
The indent changes only the whitespace. It never changes the data, so pick whatever your team or project already uses, and stay consistent.
Large numbers stay exact
Many programs read JSON numbers as ordinary decimals, which cannot hold more than about 15 or 16 significant digits. A long identifier such as 12345678901234567890 can end up rounded. JSON Formatter avoids this because it copies numbers and text exactly as written. A number like 1.50 also stays 1.50. That makes it a good way to inspect data before you pass it to anything else.
The other converters on the site, such as JSON to CSV and JSON to YAML, read JSON as ordinary data, so a number beyond that range in the source may lose its exact digits during the conversion. If an identifier matters, keep it as a string in your JSON and check it after converting.
Practical tips
- Validate before you convert. A clean check first saves guessing about which tool rejected your data.
- Format when comparing. Two files with the same layout and sorted keys are easy to compare side by side.
- Minify when size matters, and keep a formatted copy for people.
- Fix one error at a time. The tool reports the first problem it finds. After you fix it, the next one may appear.
- Watch your copy and paste. Word processors and chat apps can turn straight quotes into curly ones, which JSON does not accept as quote marks.
- Keep the original. Copy the result somewhere new rather than overwriting your source.
Large files
There is no fixed size limit, but very large files depend on your device’s memory. If the result is long, the output box shows only the first part. Copy and Download still include all of it. For a file that will not open at all, try closing other tabs first.
Where to go next
Once your JSON is valid, you may want it in another shape. CSV to JSON and JSON to CSV move between tables and JSON, and the matching guides are how to convert CSV to JSON and how to convert JSON to CSV. For configuration files, read how to convert JSON to YAML and back. If you work with older systems, how to convert XML to JSON and back covers that. To choose between formats, see CSV vs Excel vs JSON.
Frequently asked questions
Is my JSON uploaded when I format it?
No. It is checked and formatted in your browser and never leaves your device.
What does Validate do?
It only checks the JSON. A valid file gives a short summary, such as an object with 12 keys. An invalid one gives the line, column and reason.
Does the formatter change my numbers?
No. Numbers and strings are kept exactly as written, so large integers and values like 1.50 are not rounded or reformatted.
Why does it say my JSON is invalid when it looks fine?
Look for a trailing comma, single quotes, an unquoted key, a comment or curly quote marks pasted from another app. The error message and the caret under the line point to the spot.
Can it fix broken JSON for me?
No. It explains the problem and where it is, and you correct it. It does not guess what you meant.
How does Sort keys work?
Keys are sorted alphabetically at every level of nesting. The order of items inside lists never changes.
Is there a size limit?
There is no fixed limit, but very large files depend on your device memory. Copy and Download always include the complete result.