How to Format and Validate JSON Online Free
Paste JSON to check it's valid, find the line of any error, and pretty-print or minify it. Common mistakes explained. A free JSON formatter; data stays local.
Published · 4 min read
To format and validate JSON, paste it into the free JSON formatter and click Format. If the JSON is valid, you get it back neatly indented with "Valid JSON." underneath. If it isn't, you see the line and column of the first mistake, so you can fix it and try again. Minify does the reverse, squeezing it onto one line. Everything runs in your browser, so API responses, config files and private data never leave your device.
Format, validate and minify
Open the free JSON formatter:
- Paste your JSON into Your JSON.
- Choose an Indent: 2 spaces, 4 spaces or Tab.
- Click Format to pretty-print it, or Minify to strip every unneeded space and line break.
- Read the status line. "Valid JSON." means it parsed cleanly. "Not valid JSON." is followed by where and what the problem is.
- Click Copy result, or Download .json to save it as
formatted.json.
Formatting is also the quickest way to validate: the tool has to fully read the JSON before it can lay it out, so any syntax error stops it with a message.
Before and after
Minified JSON from an API is hard to read:
{"user":{"id":42,"name":"Priya","roles":["admin","editor"]},"active":true}
Formatted with 2 spaces, the structure is obvious:
{
"user": {
"id": 42,
"name": "Priya",
"roles": [
"admin",
"editor"
]
},
"active": true
}
The JSON rules that cause most errors
JSON looks like JavaScript, but it's stricter. These mistakes cause most "Not valid JSON" messages:
| Mistake | Invalid | Valid |
|---|---|---|
| Single quotes | {'name': 'Priya'} |
{"name": "Priya"} |
| Keys without quotes | {name: "Priya"} |
{"name": "Priya"} |
| Trailing comma | [1, 2, 3,] |
[1, 2, 3] |
| Comments | {"a": 1 // note} |
{"a": 1} |
| Missing comma | {"a": 1 "b": 2} |
{"a": 1, "b": 2} |
| Unclosed bracket | {"a": [1, 2} |
{"a": [1, 2]} |
| Special values | {"a": undefined} |
{"a": null} |
| Unescaped quote in text | {"q": "say "hi""} |
{"q": "say \"hi\""} |
A few more rules worth knowing:
- Strings must use double quotes only.
true,falseandnullare lowercase.- Numbers can't have leading zeros (
007), a leading+, or beNaNorInfinity. - Line breaks inside a string must be written as
\n.
Reading the error message
The error uses your browser's own JSON reader, so the exact wording varies a little between Chrome, Safari and Firefox. In Chrome, a missing comma at the end of line 1 shows up as something like "Line 2, column 1: Expected ',' or '}' after property value."
Notice that it points at line 2, not line 1. The parser reports where it noticed the problem, which is usually just after the actual mistake. So go to the line and column given, then look just before it, including the end of the previous line.
If the message says the JSON ends too soon, or points at the very end, a bracket or brace was probably opened and never closed. Count your opening and closing brackets, or format a smaller piece at a time to narrow it down.
Copying JSON from a chat app, document or web page can also bring in "smart" curly quotes (“ ”) instead of straight ones ("). They look almost the same but aren't valid. Retype the quotes, or copy from the original source.
When to minify
Minified JSON is smaller, which helps when you:
- Paste JSON into a single-line field, environment variable or command.
- Store or send a lot of it, where every byte counts.
- Compare two payloads by eye on one line.
For reading, debugging and code reviews, format it.
Two things formatting can change
Formatting keeps your data the same in almost every case. Two edge cases are worth knowing, because they apply to most JavaScript-based tools:
- Very large whole numbers lose precision. Numbers above 9,007,199,254,740,991 can't be stored exactly in JavaScript, so a 20-digit ID like
12345678901234567890comes back as12345678901234567000. If your data has IDs that long, keep them as strings in quotes. - Duplicate keys collapse. If an object has the same key twice, such as
{"a": 1, "a": 2}, only the last value is kept. Duplicate keys are usually a bug anyway, so this can help you spot one.
Next steps with your JSON
- Open it in Excel or Google Sheets: convert an array of records with the free JSON to CSV converter. The guide on converting JSON to CSV for Excel walks through it.
- Explore a big, nested file: the JSON visualizer shows it as a tree or graph.
- Read a token: if your JSON is inside a JWT, use the free JWT decoder, and see how to decode a JWT.
Format yours now
Paste your JSON, pick an indent and click Format. The free JSON formatter validates as it formats, points to errors by line and column, and keeps your data on your device.
Frequently asked questions
- How do I check if my JSON is valid?
- Paste it into the JSON formatter and click Format. Valid JSON is formatted and marked "Valid JSON."; invalid JSON shows the line, column and reason for the first error.
- Why does my JSON have an error on a line that looks fine?
- The parser reports where it noticed the problem, which is often just after the real mistake. Check the end of the line before, especially for a missing comma.
- Can JSON have comments or trailing commas?
- Not in standard JSON. Remove comments and the last comma before a closing bracket, and the JSON will validate.
- Is my JSON uploaded anywhere?
- No. Formatting and validation run in your browser, so your data never leaves your device.
- What's the difference between formatting and minifying?
- Formatting adds line breaks and indentation so people can read it. Minifying removes them so the JSON is as small as possible. The data is the same either way.
Text tools
Try the JSON Formatter
Free, no sign-up, works in your browser. Paste JSON to check that it's valid, then format it with clear indentation or minify it to one line.