How to Format & Validate JSON Online β Free Tool + Guide
What Is JSON and Why Does Formatting Matter?
JSON (JavaScript Object Notation) is the lingua franca of modern web APIs. It's what your weather app reads when it checks the forecast, what Stripe returns when you create a payment, and what your config files store when they don't have a better format. JSON is simple by design β just keys, values, arrays, and objects β but a single syntax error makes it completely unreadable by parsers.
Unformatted JSON looks like this:
{"name":"Alice","age":30,"active":true,"scores":[95,87,92],"address":{"city":"Portland","zip":"97201"}}
That's valid, but good luck reading it when the object has 40 keys and 5 levels of nesting. Pretty-printed JSON with consistent indentation is the difference between a debugging session that takes 2 minutes and one that takes 20.
Format JSON Instantly β No Install Required
Paste your JSON, click Format, and get clean, indented output with syntax validation. Runs entirely in your browser.
Open JSON Formatter βJSON Syntax: The Six Rules
JSON has six data types and a small set of rules. Break any of them and the parser throws an error β often without telling you exactly where the problem is.
| Type | Example | Notes |
|---|---|---|
| String | "hello" | Must use double quotes. Single quotes are invalid. |
| Number | 42, 3.14, -7 | No leading zeros. No NaN or Infinity. |
| Boolean | true, false | Lowercase only. Not True or TRUE. |
| Null | null | Lowercase only. |
| Array | [1, 2, 3] | Ordered list of any types. |
| Object | {"key": "value"} | Unordered key/value pairs. Keys must be strings. |
The 7 Most Common JSON Errors
1. Trailing Commas
This is the most frequent JSON mistake:
{
"name": "Alice",
"age": 30, β trailing comma β invalid JSON
}
JSON does not allow a comma after the last item in an object or array. JavaScript and many config parsers accept this (it's valid in JS), which is why it catches people off guard. JSON proper does not.
2. Single Quotes
{'name': 'Alice'} β invalid
{"name": "Alice"} β valid
JSON requires double quotes for all strings, including keys. Single quotes are JavaScript syntax, not JSON syntax.
3. Comments
{
// This is invalid JSON
"name": "Alice"
}
JSON has no comment syntax. No //, no /* */. If you need commented config files, use TOML or YAML instead. Some tools support JSON5 (a superset that adds comments), but standard JSON parsers will reject them.
4. Unescaped Special Characters in Strings
Certain characters inside strings must be escaped with a backslash: double quote (\"), backslash (\\), newline (\n), tab (\t), carriage return (\r). A raw newline inside a string value is invalid JSON.
5. Keys Without Quotes
{name: "Alice"} β invalid (JavaScript object literal, not JSON)
{"name": "Alice"} β valid
In JavaScript, object keys don't need quotes if they're valid identifiers. In JSON, keys must always be quoted strings. This is one of the most common copy-paste errors when going from JS code to a JSON file.
6. Undefined Values
JavaScript's undefined is not a valid JSON type. If you serialize a JavaScript object with undefined values using JSON.stringify(), those keys are silently dropped. If you try to include undefined literally in JSON, the parser will throw.
7. Numbers with Leading Zeros
{"zip": 07201} β invalid
{"zip": "07201"} β valid (as string)
{"zip": 7201} β valid (as number, loses the leading zero)
ZIP codes, phone numbers, and any numeric data where leading zeros matter should be stored as strings in JSON.
Pretty-Printing vs. Minifying: When to Use Each
Pretty-Print (Formatted) JSON
Use formatted JSON when:
- You're debugging an API response
- You're writing or reviewing a config file
- You're reviewing data in version control (diffs are readable)
- You're sharing JSON with other humans
The cost of pretty-printing is file size. A well-indented JSON file can be 30β50% larger than its minified equivalent due to whitespace.
Minified JSON
Use minified JSON when:
- You're serving JSON over an HTTP API at scale
- Bandwidth or payload size is a concern
- The JSON is consumed only by machines, never read by humans
Most production APIs serve minified JSON. If you're building an API that returns large payloads, consider gzip compression on top β gzip typically reduces JSON by 70β80% regardless of whether it's pretty-printed or minified, because JSON's repetitive structure compresses exceptionally well.
When to Validate JSON
Validation catches syntax errors before they cause runtime failures. You should validate JSON whenever:
- You're hand-editing a config file and about to deploy
- You're consuming a third-party API and the response looks wrong
- You're building a form that accepts JSON input from users
- An API call is returning a parse error and you need to find the offending character
A good online JSON formatter does two things simultaneously: it formats and it validates. If the input is invalid, it tells you why and where (line number, expected token). This is faster than reading a stack trace from your parser.
Validate & Format Your JSON Now
Paste minified or messy JSON and get clean, indented output with error detection. Completely free, no account needed.
Open JSON Formatter βJSON vs. Related Formats
| Format | Best For | Allows Comments? | Strict? |
|---|---|---|---|
| JSON | APIs, data exchange | No | Yes |
| JSON5 | Config files | Yes | No |
| JSONC | VSCode config | Yes | No |
| YAML | Config files, CI pipelines | Yes | No (whitespace-sensitive) |
| TOML | Rust/Python config | Yes | Yes |
| XML | Enterprise data, SOAP | Yes | Yes |