How the JSON Formatter Works
Valid JSON needs double quotes around every key and string, no trailing commas and no comments; anything else fails to parse. Paste your JSON above to pretty print it with 2 spaces, 4 spaces or tabs, minify it or sort its keys. If it is invalid, the formatter shows the line and column of the first error and what it expected there. It all runs in your browser.
The input is parsed with the browser's built in strict JSON parser, then printed again with the indentation you pick. Nothing is sent to a server, so the tool also works offline once the page has loaded. Formatting never changes the data itself, with one exception covered below: numbers too large or too precise for JavaScript.
Common JSON Errors and How to Fix Them
These are the messages the formatter shows for the mistakes people make most often. Line and column point to the character where parsing stopped, which is usually just after the real mistake.
| Input | Message shown | Fix |
|---|---|---|
{"a": 1,} | Trailing comma before } | Delete the last comma |
{'a': 1} | Property names need double quotes, not single quotes | Use "a" |
{a: 1} | Expected a property name in double quotes | Quote the key |
{"a": 1 "b": 2} | Expected ',' or '}' after a property value (missing comma?) | Add a comma after 1 |
{"a": NaN} | Unexpected word "NaN" | Use null or a number |
{"a": 007} | Numbers cannot have leading zeros | Write 7, or "007" as a string |
// note before the data | Comments are not allowed in JSON | Remove the comment |
{"dir": "C:\data"} | Invalid escape sequence in a string | Double the backslash: C:\\data |
If the error is on the last line, look for a missing closing } or ]. JSON copied from a JavaScript file often has single quotes, comments or trailing commas, all of which are legal in JavaScript and JSON5 but not in JSON.
Big Numbers Lose Precision
JSON itself allows numbers of any length, but JavaScript stores every number as a 64-bit double. Whole numbers are exact only up to 9,007,199,254,740,991 (253 − 1). Past that, digits change silently when the JSON is parsed and printed again.
| In your JSON | After formatting | Changed? |
|---|---|---|
| 9007199254740991 | 9007199254740991 | No |
| 9007199254740993 | 9007199254740992 | Yes |
| 12345678901234567890 | 12345678901234567000 | Yes |
| 0.1234567890123456789 | 0.12345678901234568 | Yes |
| 1e400 | null | Yes (too large) |
| 1.50 | 1.5 | No, same value |
The formatter checks every number and warns in the status bar when one would change. The fix is on the producing side: send long IDs, account numbers and exact decimals as strings, such as "id": "12345678901234567890".
Minified vs Indented File Size
The Sample button's JSON (one user record with 20 keys, nested 3 levels deep) in each output style:
| Style | Size | vs minified |
|---|---|---|
| Minified | 349 bytes | baseline |
| Tab indent | 461 bytes | +32% |
| 2 spaces | 525 bytes | +50% |
| 4 spaces | 653 bytes | +87% |
Deeply nested data gains more from minifying, flat arrays of short values less. Gzip, which most web servers apply, removes most of the difference in transfer, so minify for storage and logs and indent for anything a person will read.
JSON Value Types Quick Reference
| Type | Example | Rules |
|---|---|---|
| String | "New York" | Double quotes only; escape " and \; no raw line breaks |
| Number | -12.5e3 | No leading zeros, no +, no NaN or Infinity, no hex |
| Boolean | true | Lowercase true or false |
| Null | null | Lowercase; there is no undefined |
| Array | [1, "a", null] | Items separated by commas, no trailing comma |
| Object | {"key": "value"} | Keys must be strings; duplicate keys are allowed by the grammar but the last one wins here |
Need the data in a spreadsheet? The JSON to CSV converter flattens nested objects into columns, and the diff checker compares two formatted JSON files line by line.
Scheduling a job that produces this JSON? The cron expression builder writes and explains the schedule line.
JSON Formatter Guide
JSON.parse() and JSON.stringify(). No data is sent to any server. This tool works entirely offline once the page loads: you can disconnect from the internet and it will continue to work. We have no access to or logs of what you paste. Suitable for sensitive API keys, tokens, or internal JSON data.// single-line or /* block */ comments. Undefined or NaN values: only strings, numbers, booleans, null, arrays, and objects are valid. The validator in this tool shows the line and column of the first error and what it expected there."double quotes", and values can only be strings, numbers, booleans, null, arrays, or objects. JavaScript objects are more flexible: they allow unquoted keys, single quotes, trailing commas, functions as values, and comments. JSON is a strict data-interchange subset of JavaScript object syntax. This is why JSON.parse('{"key": undefined}') throws an error,undefined is a JavaScript concept, not a JSON value.JSON.parse(str) in a try-catch block. If it throws, the JSON is invalid; the error message will indicate the position. In Python: use json.loads(str) inside a try-except json.JSONDecodeError block. In Java: use ObjectMapper.readTree(str) from Jackson, wrapped in a try-catch. In Go: json.Valid([]byte(str)) returns a boolean. In Bash: echo "$json" | python3 -m json.tool validates and pretty-prints in one command.python3 -m json.tool large.json or jq . large.json for faster processing. The browser textarea may scroll slowly with very large outputs, but the formatting itself is not size-limited..json5 extension. This formatter uses the standard JSON.parse() which does not support JSON5 syntax. If you have JSON5 input with trailing commas or comments, remove them first. Babel, for example, reads .babelrc files as JSON5. True JSON validation uses strict JSON syntax only.JSON.stringify when using null, 2). 4-space indentation is the Python convention (used by json.dumps(indent=4)) and produces more spacious, readable output. Tab indentation is preferred by some editors (Vim, older conventions) and allows users to configure tab width visually. Select the style that matches your project's code style guide. This formatter defaults to 2 spaces.{"a": 1, "a": 2} becomes {"a": 2}. Other parsers may keep the first value or reject the document, so remove duplicates at the source.