JSON Formatter
Format, validate and minify JSON with syntax highlighting and real-time error detection.
All processing happens locally in your browser — your data never leaves your device.
JSON (JavaScript Object Notation) is the text format most APIs, config files and log pipelines use to exchange structured data. This formatter parses your input with the browser's native JSON.parse, then re-serializes it: Format pretty-prints with 2- or 4-space indentation, Minify strips all insignificant whitespace, and Validate only reports whether the input is valid JSON.
Validation is strict RFC 8259 JSON, the same rules your backend parser applies. Comments, trailing commas, single-quoted strings, unquoted keys and values like NaN or undefined are rejected, and the error message from the parser (usually with a position or line/column) is shown above the editors.
When parsing fails, the formatter explains the problem in plain English and marks the exact line and column. It recognises the usual culprits: trailing commas, single quotes, unquoted keys, comments, missing commas or brackets, Python-style True/None, undefined and NaN, bad escape sequences such as Windows paths, leading zeros, and HTML or JSONP pasted by mistake. Trailing commas and comments can be removed with one click. The check runs instantly in your browser; nothing is downloaded or uploaded.
Need to go further? Use JSON Compare to diff two payloads, the JSON Explainer to get a type-by-type breakdown of a structure, or the JSON to YAML converter once your JSON is valid.
- Paste or type JSON into the Input editor on the left (a sample object is loaded by default).
- Choose an indent width of 2 or 4 spaces with the Indent toggle.
- Click Format to pretty-print, Minify to produce a single-line version, or Validate to check syntax without changing the output.
- If the status bar shows an error, read the parser message for the position of the problem, fix it in the input editor, and run the action again.
- Use the copy button in the Output header to copy the result, or Clear to reset both editors.
- Format with 2-space or 4-space indentation
- Minify to a single line with all whitespace removed
- Strict syntax validation using the browser's native JSON parser
- Code editor with syntax highlighting, line numbers, code folding and bracket matching
- Character counts and one-click copy for both input and output
- Plain-English error hints with the failing line marked, plus one-click removal of trailing commas and comments
- Warns when a large number cannot be represented exactly and would be rounded
- Ctrl+Enter (Cmd+Enter on Mac) formats from anywhere on the page
- Parsing and formatting run locally; your JSON is not sent to a server
Pretty-print a minified API response (2-space indent)
Input:
{"id":42,"user":{"name":"Ada","roles":["admin","dev"]},"active":true}
Output:
{
"id": 42,
"user": {
"name": "Ada",
"roles": [
"admin",
"dev"
]
},
"active": true
}Format expands every object and array onto its own lines, which makes nested data easier to read and diff.
Minify a config object
Input:
{
"env": "production",
"port": 8080,
"features": ["auth", "billing"]
}
Output:
{"env":"production","port":8080,"features":["auth","billing"]}Minify removes whitespace between tokens only; whitespace inside string values is preserved.
Catching a trailing comma
Input:
{
"name": "Ada",
"age": 36,
}
Error (Chrome):
Expected double-quoted property name in JSON at position 32 (line 4 column 1)Trailing commas are legal in JavaScript but not in JSON. The exact message text varies by browser.
Unexpected token ' in JSON / Expected property name or '}'
Single quotes were used around keys or strings, or a key is unquoted (common when copying a JavaScript object literal or Python dict).
Replace single quotes with double quotes and wrap every key in double quotes: {"name": "Ada"}, not {name: 'Ada'}.
Expected double-quoted property name / Unexpected token }
A trailing comma after the last item in an object or array.
Delete the comma before the closing } or ]. Use the position in the error message to find it.
Unexpected end of JSON input
The input is truncated or a bracket, brace or string quote was never closed, often from copying a partial log line.
Check that every { has a matching } and every [ has a matching ]. The editor's bracket matching highlights pairs as you move the cursor.
Bad control character in string literal
A string value contains a raw line break or tab instead of the \n or \t escape sequence.
Replace literal newlines inside strings with \n and tabs with \t, or escape the text first with the JSON Escape tool.
Unexpected token / is not valid JSON at position 0
The input starts with something that is not JSON, such as a UTF-8 BOM, an HTML error page, a JSONP callback name, or a comment.
Remove any leading characters so the input begins with {, [, a quote, a number, true, false or null.
Why does valid JavaScript fail validation here?
JSON is a strict subset of JavaScript object syntax. Keys and strings must use double quotes, trailing commas and comments are not allowed, and only null, true, false, numbers, strings, arrays and objects are valid values. JSON5 or JSONC files (such as some tsconfig.json or VS Code settings files) need their comments and trailing commas removed first.
Why did a large number change after formatting?
The formatter parses input into JavaScript numbers, which are 64-bit floats. Integers above 9007199254740991 (2^53 - 1), such as 64-bit database IDs or Twitter/Snowflake IDs, lose precision and are rounded in the output. The formatter warns you when this happens; if exact digits matter, store those values as strings.
What happens to duplicate keys?
JSON.parse keeps the last occurrence of a duplicated key and silently drops the earlier ones, so the formatted output will contain only one entry. Validate will not flag duplicates as an error.
Does the formatter preserve escape sequences like \u00e9 or \/?
Not literally. Output is re-serialized from the parsed value, so \u00e9 becomes the character itself and \/ becomes /. Quotes, backslashes and control characters are still escaped. The data is equivalent, but the text may differ from the original.
Is my JSON sent to a server?
No. Parsing, formatting and the error hints all run in your browser with JavaScript; the tool makes no network requests with your data.
How do I put formatted JSON inside another JSON string?
Minify it here, then run it through the JSON Escape tool to escape the quotes and backslashes so it can be embedded as a string value.
- JSON CompareCompare two JSON objects side-by-side and detect added keys, removed keys, and changed values.
- JSON ExplainerPaste any JSON and get a plain-English breakdown of every key, type, and nested structure — no AI API needed.
- JSON Escape/UnescapeEscape and unescape JSON strings — ensure valid JSON formatting with proper character escaping.
- JSON to CSV ConverterConvert a JSON array to CSV with a header row, or turn CSV back into JSON.
- JSON to YAML ConverterConvert JSON to YAML for configuration files, or YAML back to JSON.
- JSON to XML ConverterConvert JSON objects to XML elements, or parse XML back into JSON.