JSON Formatter & Validator
Pretty-print, validate, and minify JSON instantly.
API responses and configs stay in this tabFormat and validate JSON online
About this JSON formatter
Paste any JSON and get a clean, indented version back — two spaces, four spaces, or tabs — with syntax validation. If the JSON is invalid, the exact error message and the character position where parsing stopped are shown, so you can fix it fast. You can also minify, stripping every optional space and line break for compact payloads.
Everything happens locally in your browser using the native JSON parser. Your data never leaves your device, which makes it safe for API responses, config files, and anything containing credentials or customer data.
Most "invalid JSON" errors come from expecting the format to be bigger than it is. RFC 8259 defines exactly six value types: string, number, object, array, true/false, and null. Strings use double quotes only, and because keys are strings, keys need double quotes too. Numbers cannot be NaN, Infinity, hexadecimal, or written with a leading plus or a leading zero. There are no comments and no trailing commas. There is no date type either — dates travel as ISO 8601 strings by convention, not by rule. The spec is looser than people expect in one place: a JSON document does not have to be an object or an array, so 42, "hello" and null are each a complete, valid JSON text. Earlier specifications did require an object or array at the top; RFC 8259 dropped that.
Formatting means parsing and re-serialising, and that round trip is not always lossless. Duplicate keys are the big one: RFC 8259 says names SHOULD be unique and leaves everything else undefined, so {"a":1,"a":2} comes back as {"a":2} with no warning. Integers beyond 2^53−1 lose precision, because JavaScript numbers are IEEE 754 doubles — 12345678901234567890 reformats as 12345678901234567000, and 9007199254740993 becomes 9007199254740992. A literal like 1e999 overflows to Infinity while parsing and then serialises as null. Trailing zeros disappear (1.50 becomes 1.5). And keys that look like non-negative integers get hoisted to the front in ascending numeric order, so {"10":…,"2":…,"name":…} reformats as {"2":…,"10":…,"name":…}. If any of that matters — signed payloads, Snowflake or Twitter-style IDs, financial figures — format with something built on a lossless parser instead. Python’s json module keeps arbitrary-precision integers; in JavaScript you need a BigInt-aware library.
This is a formatter and validator, not a repair tool: it tells you where the parse failed, it does not guess what you meant. It accepts strict JSON only, so a tsconfig.json with comments or a .json5 file is rejected on purpose, and NDJSON has to be fed in a line at a time. Everything runs synchronously on the page, so a file in the hundreds of megabytes will freeze the tab — for that, or for filtering rather than formatting, jq on the command line is the better tool.
JSON syntax errors and what they actually mean
When JSON.parse fails, the browser reports which rule was broken plus the offset where it gave up, in the form "at position N (line L column C)". Chrome, Edge and Node all run the V8 engine and word these messages identically; Firefox and Safari phrase the same problems differently. Positions are trimmed from the table below because they depend on your input.
| What you wrote | What Chrome reports | Fix |
|---|---|---|
| {"a":1,} | Expected double-quoted property name in JSON | Delete the trailing comma. JSON never allows one, in objects or arrays. |
| {'a':1} | Expected property name or '}' in JSON | Single quotes are JavaScript, not JSON. Use double quotes. |
| {a:1} | Expected property name or '}' in JSON | Keys are strings and must be quoted: {"a":1}. |
| {"a":1 /* note */} | Expected ',' or '}' after property value in JSON | Strip the comment. If you need comments, the file is JSONC or JSON5, not JSON. |
| {"a":NaN} | Unexpected token 'N', … is not valid JSON | NaN and Infinity are not JSON values. Use null, or send the string "NaN". |
| {"a":01} | Unexpected number in JSON | Drop the leading zero, or quote it: "01". Zip codes and account numbers belong in strings. |
| {"a":"C:\x"} | Bad escaped character in JSON | A backslash must be escaped: "C:\\x". Only \" \\ \/ \b \f \n \r \t and \uXXXX are legal. |
| A real line break inside a string | Bad control character in string literal in JSON | Write \n for a newline and \t for a tab. Raw control characters are illegal inside strings. |
The position is where the parser gave up, not always where you went wrong. The trailing comma in {"a":1,} is reported at position 7 — the closing brace — because the parser only knows something is off once it looks for the next key and finds } instead. Work backwards from the reported offset. Two more you will meet often: "Unexpected end of JSON input" means the text stops mid-structure, almost always a truncated download or a response body that was already consumed; and "Unexpected non-whitespace character after JSON" means a second document is glued onto the first, which is exactly what an NDJSON log file looks like to a strict parser.
{
"string": "double quotes only",
"number": -1.5e3,
"object": { "nested": true },
"array": [1, 2, 3],
"boolean": false,
"nothing": null
}If your file legitimately needs comments, you are not writing JSON — you are writing one of its cousins, and this tool rejects them by design. JSONC (JSON with Comments) is what VS Code uses for settings.json, tasks.json and launch.json: it adds // and /* */ comments and tolerates trailing commas, though the editor warns about those. JSON5 goes much further. It is a superset that also allows unquoted keys, single-quoted and multi-line strings, hexadecimal numbers, leading and trailing decimal points, an explicit +, and Infinity and NaN. Neither parses with JSON.parse, and neither should be POSTed to an endpoint expecting application/json. Strip the comments first, then format here.
FAQ
Is my JSON uploaded to a server?
No. Formatting and validation run entirely in your browser with JavaScript. Nothing is sent anywhere.
What does "minify" do?
It removes all unnecessary whitespace and line breaks, producing the smallest valid version of your JSON — useful for APIs and storage.
Why is my JSON invalid?
Common causes: trailing commas, single quotes instead of double quotes, unquoted keys, or comments (standard JSON allows none of these). The error message points to the exact position.