JSON Formatter
Pretty-print, minify and validate JSON. Errors are flagged with line numbers.
What is JSON?
JSON - JavaScript Object Notation - is the dominant data interchange format on the web. It is human-readable, maps cleanly onto the data structures of almost every programming language, and is far less verbose than the XML it largely replaced.
Minified JSON is what travels over the network: no whitespace, no line breaks, everything on one line. That is efficient for machines and unreadable for people, which is what a formatter fixes.
Key takeaways
- Pretty-printing adds indentation for reading; minifying strips it for transport.
- JSON supports six value types: string, number, boolean, null, object and array.
- Keys must be double-quoted strings - single quotes are invalid.
- Trailing commas and comments are not allowed in standard JSON.
- Formatting changes only whitespace; the data is identical, except integers beyond 2^53 (such as long IDs), which JavaScript rounds - the tool warns when that happens.
JSON data types
| Type | Example | Notes |
|---|---|---|
| String | "hello" | Double quotes only; single quotes are invalid |
| Number | 42, -3.14, 1.2e10 | No leading zeros, no NaN, no Infinity |
| Boolean | true, false | Lowercase only |
| Null | null | Lowercase only |
| Object | {"key": "value"} | Unordered set of key-value pairs |
| Array | [1, 2, 3] | Ordered list; may mix types |
There is no date type in JSON. Dates are conventionally sent as ISO 8601 strings such as "2026-09-14T10:30:00Z".
Formatted versus minified
The same data, both ways:
{"name":"Ada","age":36,"tags":["dev","math"]}
Formatted:
{
"name": "Ada",
"age": 36,
"tags": ["dev", "math"]
}
- Minify for API responses, network payloads and anything sent at volume - whitespace is pure overhead.
- Format for configuration files, documentation, debugging and anything stored in version control, where a readable diff matters.
Common JSON mistakes
| Invalid | Valid | Why |
|---|---|---|
| {name: "Ada"} | {"name": "Ada"} | Keys must be quoted strings |
| {'name': 'Ada'} | {"name": "Ada"} | Single quotes are not JSON |
| {"a": 1,} | {"a": 1} | Trailing commas are not allowed |
| // a comment | (remove it) | JSON has no comment syntax |
| {"n": 007} | {"n": 7} | Leading zeros are invalid |
| {"n": .5} | {"n": 0.5} | A number must start with a digit |
| {"n": NaN} | {"n": null} | NaN and Infinity are not JSON values |
| {"s": "line break"} | {"s": "line\nbreak"} | Literal newlines must be escaped |
Escape sequences
| Character | Escape | Meaning |
|---|---|---|
| " | \" | Double quote inside a string |
| \ | \\ | Literal backslash |
| / | \/ | Optional; only needed to avoid ending a script tag |
| Newline | \n | Line feed |
| Tab | \t | Horizontal tab |
| Carriage return | \r | |
| Any Unicode | \uXXXX | Four hex digits |
Control characters below U+0020 must always be escaped. Everything else can appear literally in a UTF-8 encoded document.
Indentation conventions
- Two spaces is the most common convention and the default in most tooling.
- Four spaces suits deeply nested structures where two becomes hard to follow.
- Tabs let each developer choose their own display width, but render inconsistently in some viewers.
- Minified for anything that travels over a network.
For files kept in version control, consistent formatting matters more than which convention you pick - a reformat that changes every line makes the real change impossible to review.
Frequently Asked Questions
What does formatting JSON do?
It adds indentation and line breaks so the structure is readable, without changing any of the data. Minifying does the reverse, stripping every unnecessary character to produce the smallest possible payload. Both represent exactly the same data.
Why is my JSON invalid?
The most common causes are unquoted keys, single quotes instead of double, a trailing comma after the last element, or comments - none of which JSON permits despite all being legal in JavaScript. The formatter reports the position of the first error.
Can JSON have comments?
No. Standard JSON has no comment syntax, which is a deliberate design decision that frequently frustrates people writing configuration files. JSON5, JSONC and YAML all support comments if you need them.
Are trailing commas allowed in JSON?
No. A comma after the final element of an array or object is invalid, even though JavaScript allows it. This is one of the most common causes of parse errors for developers used to writing object literals.
How do I represent a date in JSON?
There is no date type, so dates are conventionally sent as ISO 8601 strings such as "2026-09-14T10:30:00Z". Unix timestamps as numbers are the other common approach. Either way, both ends must agree on the convention.
Should I minify JSON in production?
For API responses and network payloads, yes - whitespace is pure transfer overhead at volume. For configuration files and anything in version control, keep it formatted so diffs remain reviewable. Compression at the transport layer reduces the difference considerably either way.
How many spaces should I indent JSON by?
Two is the most common convention and the default in most tooling. Four suits deeply nested structures. What matters most is consistency within a project, since a reformat that touches every line makes real changes impossible to review.
Is my JSON sent to a server?
No. Formatting and validation happen entirely in your browser. Nothing is uploaded or stored, which matters when the payload you are debugging contains real customer data.