What the JSON Formatter does
The JSON Formatter rewrites JSON so that people can read it: every key and value gets its own line, and nested objects and arrays are indented. Before it writes a single line, it validates the text against the JSON standard, RFC 8259 (opens in a new tab). Text that is not valid JSON gets no output; you see where each problem is and how to fix it instead.
How to format and validate JSON
- Paste your JSON into the input, or open or drop a
.jsonfile. - Choose the indentation, and turn on Sort keys if you want the keys in a fixed order.
- Read the output. It follows your typing for input under 1 MB; for larger input, press Format or Ctrl+Enter.
- If the tool lists problems, select one to jump to its place in the input, then fix it there.
- Copy the formatted JSON, or download it as a file.
Examples
Input
{"orderId":98765432109876543210,"price":19.90,"paid":true}
Output
{
"orderId": 98765432109876543210,
"price": 19.90,
"paid": true
}
Input
{
// Check types strictly
"strict": true,
"target": "es2022",
}
Output
{
// Check types strictly
"strict": true,
"target": "es2022"
}
Input
{'name': 'Ada', 'active': True}
Problem reported
Line 1, column 2: JSON strings and keys use double quotes, not single quotes. Write it in double quotes, like "text". (JSON_SINGLE_QUOTE)
Options
| Option | Values | Default | When to change it |
|---|---|---|---|
| Indent | 2 spaces, 4 spaces, Tab | 2 spaces | Two spaces is the most common style for JSON. Pick the style of the project the JSON belongs to. |
| Sort keys | On, Off | Off | Turn it on to order the keys of every object, at every level, by Unicode code point. Two documents with the same data then line up, which makes a diff easy to read. Arrays keep their order. |
| Allow comments (JSONC) | On, Off | Off | Turn it on for files that allow comments and trailing commas, such as tsconfig.json or VS Code settings. Comments stay where they were; trailing commas are left out of the output. |
Common errors and fixes
| Code | What it means | How to fix it |
|---|---|---|
JSON_Error | A character appears where JSON does not allow it: often a curly quote, a non-breaking space or a bracket that closes the wrong thing. | Replace curly quotes with straight double quotes, delete invisible spaces, and check that every { and [ closes with its own } or ]. |
JSON_Error | Two values or members follow each other without a comma, often after a line was added by hand. | Add a comma at the end of the line before the reported position. |
JSON_Error | A comma comes right before } or ]. JavaScript allows it, JSON does not. | Delete the comma, or turn on Allow comments (JSONC) if the file is JSONC. |
JSON_Error | A string or key is in single quotes, as Python and JavaScript print them. | Use double quotes. When converting a Python dictionary, also write True, False and None as true, false and null. |
JSON_Error | A key has no quotes, as in a JavaScript object literal. | Put the key in double quotes. |
JSON_Error | A bare word such as True, None, undefined or NaN stands where a value belongs. JSON knows only true, false and null. | Write true, false or null in lowercase, or put text in double quotes. JSON has no NaN or Infinity. |
JSON_Error | The input has // or /* */ comments, which strict JSON does not allow. | Delete the comments, or turn on Allow comments (JSONC) to keep them. |
JSON_Error | The input stops before every object and array is closed, often because the copy was cut short. | Copy the whole document again, or add the missing } or ] the message names. |
JSON_Error | A string holds a raw tab or line break. JSON strings must escape them. | Write a tab as \t and a line break as \n. A line break inside a string often means its closing quote is missing. |
JSON_Error | A backslash starts something JSON does not know as an escape, such as the \U in a Windows path. | Double the backslash, as in C:\\Users, or use one of JSON's escapes. |
JSON_Error | A number has a form JSON does not accept: a leading zero, a plus sign, a leading or trailing point, or hexadecimal. | Write it in plain decimal; the message suggests the exact form, such as 0.5 for .5. |
JSON_Error | More text follows the end of the JSON value: a second document, as in JSON Lines, or leftover characters. | Keep one value per document. Wrap several values in an array, or format JSON Lines one line at a time. |
JSON_Warning | An object uses the same key twice. Both members are kept, but most programs read only one of them. | Remove the member you do not want; the message points to both. |
Strict JSON and JSONC
JSON as RFC 8259 defines it has no comments and no trailing commas, so most programs that read JSON reject both. Some tools read a relaxed form usually called JSONC, JSON with comments: TypeScript's tsconfig.json, VS Code's settings.json and the Dev Containers devcontainer.json are common examples.
With Allow comments (JSONC) off, the formatter checks strict JSON and lists every comment and trailing comma as an error, so you can see what to remove before you send the data to an API. Turn it on to format a JSONC file: comments stay where they were, and each trailing comma is left out with a note.
Why big numbers change in other tools
JavaScript stores every number as a 64-bit floating-point value. It can hold every integer only up to 9,007,199,254,740,991 (2^53 − 1), and about 15 to 17 significant digits in all. A tool that formats JSON with JSON.parse and JSON.stringify rewrites anything beyond that: the ID 12345678901234567890 comes out as 12345678901234567000, and a decimal with 30 digits is rounded.
This formatter never converts numbers. It copies each number's text from your input, so 1.0, 1E+2 and long IDs stay exactly as written. When a value would change in a JavaScript program, a note says what JSON.parse would turn it into. If such values travel between systems, sending them as strings is the safe choice.
Duplicate keys
RFC 8259 says that the names in an object should be unique, but it does not forbid repeats, and parsers handle them differently. Many keep only the last value, as JavaScript's JSON.parse does; others reject the object, and some report every pair. A formatter built on JSON.parse therefore drops all but the last member without a word.
This formatter keeps every member in its place and warns about each repeat, with the line and column of the first one. Keys that differ only in their escapes, like "a" and "\u0061", count as the same key. With Sort keys on, repeated keys stay next to each other in their original order.