- Home
- Tools
- Developer Tools
- JSON Formatter
JSON Formatter
Format, validate and minify JSON, with the exact spot of any syntax error.
Nothing to paste? , or .
Result
What makes JSON valid
JSON is defined in two short documents, RFC 8259 and ECMA-404. The grammar is strict on purpose, so that a parser never has to guess. Most "invalid JSON" comes from writing it as if it were JavaScript or Python:
| Mistake | Not JSON | JSON |
|---|---|---|
| Single quotes | {'name': 'Ada'} | {"name": "Ada"} |
| Keys without quotes | {name: "Ada"} | {"name": "Ada"} |
| A comma after the last item | [1, 2, 3,] | [1, 2, 3] |
| Comments | [1, 2] // primes | [1, 2] |
NaN, Infinity, undefined | {"ratio": NaN} | {"ratio": null} |
| Python's spelling | {"ok": True, "x": None} | {"ok": true, "x": null} |
| Leading zeros, hexadecimal | [007, 0x1F] | [7, 31] |
| A real line break in a string | "first line\nsecond line" |
A backslash inside a string starts an escape, and only \", \\, \/, \b, \f, \n, \r, \t and \uXXXX exist. That is why a Windows path needs its backslashes doubled: "C:\\Users\\ada".
When the text is not valid, you get the line and column of the first problem and the reason in words. The position is worked out by this page and not taken from the browser's own error message, so it reads the same in Chrome, Firefox and Safari. For a missing comma it points at the spot where the comma belongs, which is usually one line above the place where a parser gives up.
What Repair does
Repair fixes the mistakes that can only mean one thing. It removes comments and trailing commas, adds missing commas, turns single and curly quotes into double quotes, puts quotes around bare keys and rewrites True, False and None. NaN, Infinity and undefined become null, which is also what JavaScript's JSON.stringify writes for NaN and Infinity.
It tells you what it changed, it leaves your layout alone, and it stops at anything it would have to guess at. 007 is an example: it could be the number seven or a code that needs its zeros.
Minified or formatted
Both hold exactly the same data, because spaces and line breaks between values mean nothing in JSON. The sample order on this page is 372 bytes minified and 606 bytes with two-space indentation. Send the short form over the network and keep the indented form for people to read.
Escape non-ASCII writes é as \u00e9. The data stays the same; it is for systems that only pass plain ASCII through safely.
Does the order of keys matter?
Not to a parser. The standard describes an object as an unordered collection of name/value pairs, so {"a": 1, "b": 2} and {"b": 2, "a": 1} are the same object. Sorting keys helps people, and it helps tools that compare text: two exports of the same data line up in a diff once their keys are in the same order. Keys are sorted by character code, so capitals come before lowercase letters. Arrays are never reordered, because their order is data.
Using the same key twice in one object is not forbidden, but programs disagree on what it means and most keep only the last value. You get a warning when it happens.
Large numbers
JSON puts no limit on the size of a number. JavaScript does, and so do many other programs: they store numbers as 64-bit floats, which hold whole numbers exactly only up to 9,007,199,254,740,991. Above that, digits are rounded. JSON.parse reads 9007199254740993 as 9007199254740992, which is a different database ID.
This formatter never converts a number. 12345678901234567890 and 1.50 come out exactly as they went in, and you get a warning when a number would not survive in JavaScript. If the data is yours to change, send such IDs as strings.
Nothing is uploaded
The JSON is read by code running on this page. It is not sent anywhere or stored, which makes it safe to paste API responses and configuration with real data in them. Only your options, such as the indentation, are remembered for next time.