Available actions
- Format: expand compact JSON with two spaces, four spaces or tabs for indentation.
- Validate: check syntax as you type and show the line, column and nearby text when parsing fails.
- Minify: remove insignificant whitespace and report the change in size.
- Sort keys: alphabetize object keys recursively so two configuration files are easier to compare.
- Unescape JSON string: parse a JSON document that was encoded inside another string, as often happens in structured logs.
Common JSON syntax errors
Strict JSON has a small grammar. These five mistakes account for many parsing failures.
Trailing commas
JavaScript object literals can allow trailing commas, but JSON cannot. A comma after the final property can produce an Unexpected token } error:
{
"name": "api",
"port": 8080, ← the comma after the last pair is invalid
}
Single quotes
JSON strings use double quotes, and object keys must also be quoted. {name: 'api'} is a JavaScript object literal, not valid JSON.
Comments
JSON does not allow // or /* */ comments. Some tools, including VS Code, accept comments in JSONC files, but a standard JSON parser rejects them. For annotations, use a "_comment" key or a format such as YAML or TOML.
NaN, Infinity and undefined
JSON has no NaN, Infinity or undefined value. JSON.stringify converts NaN and Infinity to null, and it omits object properties whose value is undefined. Check for this conversion when a field disappears between a service and its client.
Unescaped control characters in strings
A newline, tab or backslash inside a JSON string must be escaped as \n, \t or \\. Raw control characters often appear when code inserts a stack trace or Windows path without passing it through a JSON serializer.
Reading the error message
A browser may report a character offset for a parse error. The formatter converts that offset to a line and column and includes nearby text to make the location easier to find.
The reported position is where the parser stopped, which can be after the actual mistake. For example, a missing comma on one line may be reported at the start of the next line. Check the preceding line when the marked location looks correct.
When to minify JSON
Formatting makes JSON easier to read. Minification removes whitespace before data is transferred. An indented document may shrink by 20–30% before transport compression, but two caveats matter.
First, gzip and Brotli compress repeated whitespace well, so minifying before compression often changes the final size by less than 5%. Second, keep files that people edit in a readable format. Minified configuration files produce difficult diffs and avoidable merge conflicts.
Sorting keys before a comparison
JSON object order has no semantic meaning, although serializers commonly preserve insertion order. Two equivalent configuration files can therefore produce a large diff when their keys appear in a different sequence.
Run both files through Sort keys before comparing them. With the order normalized, the diff shows changes in values and membership instead of changes in key order.
Using JSON tools from the command line
For scripts and local files, jq provides the same format, minify, sort and validation operations:
# Format with indentation
jq '.' input.json
# Remove insignificant whitespace
jq -c '.' input.json
# Sort every object key
jq -S '.' input.json
# Validate with exit code 0 for success
jq empty input.json && echo "valid"
# Use Python when jq is unavailable
python3 -m json.tool input.json
This page and the default jq mode both load the full document into memory. For files that are too large to hold comfortably, use a streaming parser such as jq --stream or Python’s ijson.
Frequently asked questions
Is my JSON uploaded anywhere?
No. Parsing, formatting and validation use the browser’s built-in JSON engine. This tool does not send the input to a server.
Why does my JSON fail even though it looks correct?
Check for a trailing comma, single-quoted strings, unquoted keys, comments or curly quotation marks pasted from another application. Strict JSON requires quoted keys and straight double quotes.
What is the difference between JSON and JSON5 or JSONC?
JSON5 and JSONC extend JSON with features such as comments and trailing commas. JSON5 also permits unquoted keys and single-quoted strings. Standard JSON parsers reject those extensions. This tool validates strict JSON as defined by RFC 8259.
Can it handle very large files?
The browser must hold the complete document and its parsed structure in memory. For a file that makes the page slow or unresponsive, use a streaming command-line parser instead.
What does "Unescape string" do?
JSON embedded inside another JSON string has backslashes before its quotation marks. Unescape JSON string parses that outer string, parses the recovered document and then formats it.