A JSON formatter takes compact or messy JSON and rewrites it with consistent indentation and one value per line, so you can read the structure at a glance. A good formatter also validates the document, telling you exactly where the syntax breaks when it is not valid JSON.
Paste any API response, config file or log line into our free JSON formatter and it validates the input as you type, then lets you pretty-print, minify, sort keys or repair common mistakes. This guide covers the JSON syntax rules, how to find errors fast, and when to format versus minify.
What a JSON formatter does
JSON (JavaScript Object Notation) is a text format for structured data, defined in RFC 8259. Machines do not care about whitespace, so APIs usually send JSON on a single line to save bytes. Humans need line breaks and indentation to see which value belongs to which object.
A formatter parses the text into data, then serializes it again with the layout you choose. Because it has to parse first, formatting and validation happen in the same step: if the parser cannot read the input, there is nothing to format, and you get an error instead.
| Action | What it does | Use it for |
|---|---|---|
| Format (pretty-print) | Adds line breaks and 2-space, 4-space or tab indentation | Reading, debugging, code review |
| Minify | Removes all optional whitespace | Request bodies, storage, config values |
| Sort keys | Orders object keys alphabetically at every level, keeps array order | Comparing two documents |
| Validate | Reports the line and column where parsing failed | Finding syntax errors |
Example: before and after formatting
A minified API response is valid but hard to scan:
{"id":42,"name":"Ada","roles":["admin","editor"],"active":true}
Formatted with 2-space indentation, the same data becomes:
{
"id": 42,
"name": "Ada",
"roles": [
"admin",
"editor"
],
"active": true
}
JSON syntax rules (RFC 8259)
Most "invalid JSON" errors come from habits carried over from JavaScript, Python or YAML. Valid JSON follows these rules:
- Six value types only: object, array, string, number,
true/false, andnull. - Double quotes only: strings and object keys must use
", never single quotes, and keys must always be quoted. - No trailing commas:
[1, 2, 3,]is invalid. - No comments: neither
//nor/* */is part of the format. - Lowercase literals:
true,falseandnull, notTrueorNULL. - Plain decimal numbers: no leading zeros (
007), no hex, and noNaNorInfinity. - UTF-8 text: RFC 8259 requires UTF-8 when JSON is exchanged between systems.
How to find and fix JSON syntax errors
When parsing fails, our formatter reports the position, for example "Invalid JSON at line 4, column 3". That is where the parser gave up, which is often just after the real mistake. Take this input:
{
"id": 42,
"name": "Ada"
"active": true
}
The error points to line 4, but the fix belongs at the end of line 3: a missing comma after "Ada". Always check the line above the reported position too.
| Error | Invalid | Valid |
|---|---|---|
| Trailing comma | {"a": 1,} |
{"a": 1} |
| Single quotes | {'a': 1} |
{"a": 1} |
| Unquoted key | {a: 1} |
{"a": 1} |
| Comment | {"a": 1 /* id */} |
{"a": 1} |
| Smart quotes from a word processor | {“a”: 1} |
{"a": 1} |
The Repair button fixes four of these automatically: it removes comments, removes trailing commas, converts smart quotes to straight quotes, and strips a byte-order mark. It does not guess at single quotes, unquoted keys or missing commas, because those fixes can change meaning. The status bar lists every change it made.
How to use the JSON Formatter
- Open the JSON formatter and paste your JSON into the Input JSON box (up to 100,000 characters). Click Example if you want sample data to try.
- Read the status bar. It shows "Valid JSON" with the size in bytes and nesting depth, or the line, column and reason for an error.
- Pick an indentation (2 spaces, 4 spaces or Tab), then click Format, Minify or Sort keys. Use Repair if the input has comments or trailing commas.
- Switch to the Tree view to expand nested objects and copy the exact path or value of any node.
- Switch to Inspect to run a path query such as
team[1].nameor$["complex key"], and to see counts of keys, arrays, scalars and value types. - Click Copy or Download to take the result with you.
Tips and common mistakes
- Minify for machines, format for people. Whitespace has no meaning in JSON, so both versions hold identical data.
- Sort keys before comparing. Two API responses with the same data in a different key order look completely different line by line. Sort both, then paste them into the text diff viewer to see only real changes.
- Formatting re-serializes the data. Escapes such as
\u00e9come back asé, and if an object repeats a key, only the last value survives. Our formatter warns you about every repeated key. RFC 8259 says keys should be unique for this reason. - Keep very large IDs as strings. Integers above 9,223,372,036,854,775,807 cannot be stored exactly by most parsers. Our formatter keeps them digit for digit, but the code that reads your JSON may not, so send 64-bit IDs as strings.
- Mind sensitive data. Our formatter processes input on our server. Remove API keys, tokens and personal data before pasting anything from production.
Once your JSON is valid, you can turn it into other formats: convert config files with the JSON to YAML converter, or paste fixtures into PHP code with JSON to PHP array. JSON also sits inside other formats you may need to unpack, such as the payload of a token covered in our guide on how to decode a JWT.
Frequently asked questions
What is a JSON formatter?
A JSON formatter is a tool that parses JSON and rewrites it with consistent indentation and line breaks so it is easy to read. Most formatters, including ours, also validate the syntax and report where an error occurs.
How do I check if my JSON is valid?
Paste it into a JSON validator such as our JSON formatter. If it parses, the status shows "Valid JSON"; if not, you get the line, column and reason, and the real mistake is usually at or just before that position.
Can JSON have comments?
No. Standard JSON as defined in RFC 8259 has no comment syntax, so // and /* */ make a document invalid. Some tools accept JSON with comments (often called JSONC), but strict parsers reject it.
What is the difference between pretty-printed and minified JSON?
Pretty-printed JSON adds line breaks and indentation for readability, while minified JSON removes all optional whitespace to make the payload smaller. Both contain exactly the same data.
Does formatting JSON change the data?
Formatting changes only whitespace for normal documents. The edge case is duplicate keys: only the last value is kept, and our formatter warns you when that happens. Integers too large for 64 bits are kept digit for digit.
Why are trailing commas invalid in JSON?
The JSON grammar only allows a comma between two values, so a comma before a closing bracket or brace is a syntax error. JavaScript allows trailing commas in code, which is why they often slip into JSON by habit.