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.
Method and sources. JSON grammar from RFC 8259 and ECMA-404; parsing and printing use the ECMAScript JSON.parse and JSON.stringify functions built into your browser. Numbers are IEEE 754 double precision values, so integers are exact up to 253 − 1 (Number.MAX_SAFE_INTEGER). The precision table and the size table were produced by running the same code as the tool in Node.js.
Scheduling a job that produces this JSON? The cron expression builder writes and explains the schedule line.
JSON Formatter Guide
What is JSON and why does it need formatting?
JSON (JavaScript Object Notation) is a lightweight data format used to exchange data between applications and APIs. Minified JSON has all whitespace removed for network efficiency, making it unreadable. Formatted JSON adds indentation and line breaks to make it human-readable without changing its meaning. APIs commonly return minified JSON; this tool beautifies it instantly so you can read and debug it.
Is my JSON data private and safe to paste here?
Yes, completely. All formatting happens in your browser using JavaScript's built-in 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.
What are the most common JSON syntax errors?
The most common errors: Trailing commas after the last item in an object or array (not allowed in JSON, but allowed in JavaScript). Single quotes instead of double quotes for strings and keys. Unquoted keys, all keys must be in double quotes. Comments, JSON does not support // 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.
What is the difference between JSON and a JavaScript object?
JSON is a strict text format: all keys must be in "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.
How do I validate JSON programmatically?
In JavaScript: wrap 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.
What does minify JSON mean and when should I use it?
Minifying JSON removes all non-essential whitespace (spaces, tabs, newlines) to produce the most compact valid JSON string. Use minification when sending JSON over a network (API responses, webhooks) to reduce payload size and improve performance. The sample on this page is 349 bytes minified and 525 bytes with 2-space indentation, so minifying saves about a third. In development, use formatted JSON for readability. In production API responses, minify automatically: frameworks like Express.js and FastAPI do this by default. Use the Minify button above to compact your JSON for network use.
What is the maximum size of JSON this tool can handle?
This tool processes JSON entirely in your browser's JavaScript engine. In practice, it handles up to several megabytes of JSON without issues on modern browsers. Very large JSON files (10MB+) may cause a brief pause during formatting but will complete successfully. For JSON files over 50MB, consider using a command-line tool: 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.
What is JSON5 and is it supported here?
JSON5 is a superset of JSON that adds JavaScript-like features: unquoted keys, single quotes, trailing commas, comments, and multi-line strings. It was created to make configuration files more human-friendly. JSON5 files use the .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.
How do I sort JSON keys alphabetically?
Use the Sort Keys button above. Sorting keys alphabetically makes it easier to scan large JSON objects, compare two JSON responses side-by-side, or produce deterministic output for testing. The sort is applied recursively: all nested objects are also sorted. Note that JSON technically does not guarantee key order (objects are unordered), but in practice most parsers preserve insertion order. Sorted JSON is functionally identical to unsorted JSON: any valid parser will produce the same data regardless of key order.
What is the difference between 2-space, 4-space, and tab indentation?
All three produce valid, functionally identical JSON: the difference is visual style. 2-space indentation is the most compact and common in web APIs and JavaScript projects (the default in Node.js 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.
Why did a large number change after formatting?
JavaScript parses every JSON number as a 64-bit double, which is exact for whole numbers only up to 9,007,199,254,740,991. A value such as 12345678901234567890 comes back as 12345678901234567000. The formatter warns you when this happens. Keep long IDs and exact decimals as strings in JSON to avoid it.
Are duplicate keys allowed in JSON?
The grammar does not forbid them, but RFC 8259 says names within an object should be unique because parsers disagree on what to do. JavaScript, and therefore this formatter, keeps the last value: {"a": 1, "a": 2} becomes {"a": 2}. Other parsers may keep the first value or reject the document, so remove duplicates at the source.