JSON Formatter
Format, validate, and minify JSON. Paste or type JSON on the left, see the result on the right.
How it works
This tool parses your input using the browser's native JSON.parse() and re-serializes it with JSON.stringify(). In
format mode, it adds indentation (2 or 4 spaces). In minify mode, all whitespace is
stripped. In validate mode, it checks whether the input parses without error.
When parsing fails, the tool extracts the error position from the browser's syntax error message and maps it to a line and column number. This helps you locate the exact character that caused the failure.
After a successful parse, the tool walks the parsed structure to count value types, nesting depth, total keys, and byte size. These stats appear below the output.
JSON syntax reference
JSON (JavaScript Object Notation, RFC 8259) is a text format for structured data. Despite its name, JSON is language-independent and used across virtually every programming language and API. A valid JSON document is one of six types:
- String — double-quoted Unicode text. Supports escape
sequences:
\" \\ \/ \b \f \n \r \t \uXXXX. Single quotes are not valid. - Number — integer or decimal. Supports scientific
notation (
1.5e10). No leading zeros, no hex, noNaN, noInfinity. Octal (0777) is not valid. - Boolean — lowercase
trueorfalseonly.True,TRUE, andyesare not valid. - Null — lowercase
nullonly.None,undefined, andnilare not valid. - Object — unordered set of key-value pairs. Keys must be double-quoted strings. Duplicate keys are technically allowed by the spec but discouraged — most parsers use last-wins behavior.
- Array — ordered list of values. Elements can be any type, including mixed types.
Common edge cases
Trailing commas. The most common JSON error. Unlike
JavaScript, JSON does not allow a comma after the last element:
[1, 2, 3,] is invalid. Remove the trailing comma.
Comments. JSON has no comment syntax. Lines starting
with // or blocks wrapped in
/* */ will cause parse errors. Use JSONC or JSON5 if you
need comments.
Single quotes. JSON requires double quotes for both
keys and string values. {'key': 'value'}
is invalid — use {"key": "value"}.
Unquoted keys. Object keys must be double-quoted strings.
{name: "test"} is valid JavaScript but invalid
JSON.
Number precision. JSON numbers are parsed as IEEE 754 double-precision floats. Integers beyond 253 - 1 (9,007,199,254,740,991) lose precision. APIs handling large IDs (like Twitter/X snowflake IDs) often encode them as strings for this reason.
Unicode escapes. The
\uXXXX escape represents a UTF-16 code unit. Characters
outside the Basic Multilingual Plane (like emoji) need surrogate pairs:
\uD83D\uDE00 for 😀. Most editors handle this automatically,
but hand-editing Unicode escapes is error-prone.
Duplicate keys. RFC 8259 says object keys "SHOULD be unique" but doesn't forbid duplicates. In practice, most parsers silently use the last value for a duplicate key. Some security vulnerabilities have exploited inconsistent duplicate-key handling between parsers.
Deeply nested structures. The spec sets no depth limit,
but most parsers impose one (e.g., Python's json module
defaults to 100). Extremely deep nesting can cause stack overflows in recursive parsers.
BOM and encoding. JSON must be UTF-8 (RFC 8259). A
byte order mark (BOM, \xEF\xBB\xBF) at the start of
a file will cause most parsers to reject it. Some tools add a BOM when saving UTF-8
files — remove it if you get an "unexpected token" error at position 0.
Whitespace. Only four characters count as insignificant
whitespace in JSON: space (0x20), tab (0x09), newline (0x0A), and carriage return (0x0D). Other whitespace characters (like non-breaking space, 0xA0) inside strings are valid content but will cause errors if used outside strings.
JSON vs similar formats
JSON vs JSONC. JSONC (JSON with Comments) allows
// and /* */
comments. Used by VS Code settings, TypeScript tsconfig.json, and other config files. Not valid JSON — most APIs won't accept it.
JSON vs JSON5. JSON5 extends JSON with unquoted keys, single-quoted strings, trailing commas, hex numbers, multi-line strings, comments, and more. Common in config files but not interchangeable with JSON.
JSON vs YAML. YAML is a superset of JSON (valid JSON is valid YAML). YAML adds indentation-based nesting, comments, anchors, and more types. YAML is more human-writable but more complex to parse and has a larger attack surface. JSON is the standard for APIs; YAML is common for configuration.
JSON vs TOML. TOML uses [sections] and key = value syntax with native date/time support.
Popular for config files (Cargo.toml, pyproject.toml). Simpler than YAML but less expressive
than JSON for deeply nested data.
FAQ
What is valid JSON?
Valid JSON follows RFC 8259. It supports six types: strings (double-quoted), numbers, booleans (true/false), null, objects (key-value pairs with string keys), and arrays. Trailing commas, single quotes, comments, and unquoted keys are not allowed. The root value can be any type.
What is the difference between formatting and minifying?
Formatting adds indentation and newlines for readability. Minifying strips all unnecessary whitespace for the smallest output. Both parse and re-serialize the JSON, so they also validate it.
Why does my JSON have a trailing comma error?
JSON does not allow trailing commas after the last element, unlike JavaScript. Remove the comma after the last value in your object or array.
Can JSON contain comments?
No. RFC 8259 does not support comments. Use JSONC (VS Code config format), JSON5, YAML, or TOML if you need comments in configuration files.
Does this tool send my data to a server?
No. All processing happens in your browser. No data is transmitted. Verify by checking your browser's network tab while using the tool.
What causes "Unexpected token" errors?
Common causes: single quotes instead of double quotes, unquoted property names, trailing commas, JavaScript values like undefined or NaN, comments, missing commas between elements, and BOM characters at the start of the file.
Related tools
- Epoch Converter — Convert Unix timestamps to human-readable dates and back
- Timezone Comparator — Compare times across multiple time zones side by side
- Paycheck Estimator — Calculate take-home pay after federal and state taxes
- Salary to Hourly — Convert annual salary to hourly rate and vice versa
