JSON Formatter & Validator
Format JSON with 2-space indentation, or minify it to a single line. Invalid input produces a specific error message instead of a blank result. Everything runs in your browser.
How formatting and minifying work
Both operations parse the input into a data structure and then serialize it again. Formatting writes it back with 2-space indentation and line breaks, minifying writes it with no whitespace at all.
A useful side effect: because the input must parse successfully before anything is written back, this doubles as a validator. If the output appears, the JSON is syntactically valid.
Minifying matters for transport. Whitespace in a JSON payload is meaningless to a parser but still costs bandwidth, so APIs typically send minified JSON and formatting is applied only for human reading.
JSON is stricter than JavaScript
Nearly every JSON error comes from assuming JSON accepts what JavaScript object literals accept. It does not. JSON is a deliberately minimal subset.
| Valid in JavaScript | Valid in JSON | Why |
|---|---|---|
{name: "x"} | No | Keys must be in double quotes |
{'name': 'x'} | No | Single quotes are not allowed anywhere |
{"a": 1,} | No | Trailing commas are forbidden |
// comment | No | JSON has no comment syntax |
{"a": undefined} | No | Only null exists, not undefined |
{"a": 0x1F} | No | Numbers must be decimal |
{"a": .5} | No | A leading digit is required, use 0.5 |
{"a": NaN} | No | NaN and Infinity are not JSON values |
The restrictions are intentional. JSON was designed to be trivially parseable in any language, so anything ambiguous or language-specific was left out.
What JSON does allow
The complete set of JSON value types is short:
- Object:
{"key": value}, keys must be double-quoted strings - Array:
[value, value] - String: double-quoted, with backslash escapes
- Number: decimal, optionally with a fraction and exponent
- Boolean:
trueorfalse, lowercase only - Null:
null, lowercase only
Notably absent: dates, binary data, and comments. Dates are conventionally
sent as ISO 8601 strings such as "2026-07-28T14:30:00Z", binary
data as Base64 strings.
Examples
| Input | Formatted |
|---|---|
{"a":1,"b":[1,2]} |
{
"a": 1,
"b": [
1,
2
]
} |
Common errors and their causes
| Broken input | Problem | Fix |
|---|---|---|
{name: "Ada"} | Unquoted key | {"name": "Ada"} |
{"a": 1,} | Trailing comma | {"a": 1} |
{'a': 1} | Single quotes | {"a": 1} |
{"a": "he said "hi""} | Unescaped quote | {"a": "he said \"hi\""} |
{"a": True} | Capitalized boolean | {"a": true} |
Practical notes
Large numbers lose precision
JSON numbers are parsed as IEEE 754 doubles in JavaScript, which safely
represent integers only up to 253. A 64-bit database ID such as
9007199254740993 silently loses precision. The standard
workaround is to transmit such IDs as strings.
Key order is not guaranteed
The JSON specification defines objects as unordered. Most implementations preserve insertion order in practice, but relying on it is unsafe. If order matters, use an array.
Escaping inside strings
Within a JSON string, the backslash, double quote, and control characters
must be escaped. Newlines become \n, tabs \t, and
a literal backslash \\. Forgetting to escape backslashes in
Windows file paths is a frequent cause of parse failures.
JSON versus JSONC and JSON5
Some tools accept extended dialects. JSONC allows comments and is used by VS Code configuration files, JSON5 adds unquoted keys, trailing commas, and more. Neither is standard JSON, and generic parsers will reject them.
Frequently asked questions
Why does my input get rejected?
Most often because of a trailing comma, single quotes, or unquoted keys. All three are legal in JavaScript object literals but invalid in JSON. The error message names the position where parsing failed.
Can JSON contain comments?
No. The format has no comment syntax. If you need annotations, add a
regular field such as "_comment", or use a dialect like JSONC if
your parser supports it.
Does this handle very large JSON?
Yes, within your browser's memory limits. There is an input length guard to prevent the page freezing on an accidental multi-megabyte paste.
How should dates be represented in JSON?
JSON has no date type. The convention is an ISO 8601 string such as
"2026-07-28T14:30:00Z", which sorts correctly as text and parses
reliably in every language.
Why do large IDs come back wrong?
JavaScript parses JSON numbers as doubles, which lose precision above 253. Send large 64-bit identifiers as strings to preserve them exactly.
Is my JSON sent to a server?
No. Parsing and formatting happen entirely in your browser, which means you can safely format payloads containing production data or tokens.
Related tools
- JSON to C# classes, to generate typed models from a payload
- CSV and JSON converter, for tabular data
- Text diff viewer, to compare two JSON documents
- All developer tools