Skip to content

JSON Formatter & Validator

Paste JSON to pretty-print it with 2-space, 4-space or tab indentation and check that it is valid. Errors show the line, the column and a fix, and numbers, strings and duplicate keys stay exactly as you wrote them.

Runs locally in your browser

Input

1 line · 181 characters
{"order":{"id":12345678901234567890,"status":"shipped","total":59.90,"items":[{"sku":"TV-55-OLED","qty":1},{"sku":"HDMI-2M","qty":2}],"customer":{"name":"Ada Lovelace","vip":true}}}

Output

Formatted JSON appears here

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

  1. Paste your JSON into the input, or open or drop a .json file.
  2. Choose the indentation, and turn on Sort keys if you want the keys in a fixed order.
  3. Read the output. It follows your typing for input under 1 MB; for larger input, press Format or Ctrl+Enter.
  4. If the tool lists problems, select one to jump to its place in the input, then fix it there.
  5. Copy the formatted JSON, or download it as a file.

Examples

Long IDs and prices keep their exact digits

Input

{"orderId":98765432109876543210,"price":19.90,"paid":true}

Output

{
  "orderId": 98765432109876543210,
  "price": 19.90,
  "paid": true
}
A tsconfig.json with a comment and a trailing comma

Input

{
  // Check types strictly
  "strict": true,
  "target": "es2022",
}

Output

{
  // Check types strictly
  "strict": true,
  "target": "es2022"
}
A Python dictionary pasted as JSON

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

Options
OptionValuesDefaultWhen to change it
Indent2 spaces, 4 spaces, Tab2 spacesTwo spaces is the most common style for JSON. Pick the style of the project the JSON belongs to.
Sort keysOn, OffOffTurn 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, OffOffTurn 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

Common errors and how to fix them
CodeWhat it meansHow to fix it
JSON_UNEXPECTED_TOKENErrorA 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_MISSING_COMMAErrorTwo 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_TRAILING_COMMAErrorA 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_SINGLE_QUOTEErrorA 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_UNQUOTED_KEYErrorA key has no quotes, as in a JavaScript object literal.Put the key in double quotes.
JSON_INVALID_LITERALErrorA 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_COMMENTErrorThe input has // or /* */ comments, which strict JSON does not allow.Delete the comments, or turn on Allow comments (JSONC) to keep them.
JSON_UNEXPECTED_ENDErrorThe 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_CONTROL_CHARACTERErrorA 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_INVALID_ESCAPEErrorA 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_INVALID_NUMBERErrorA 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_TRAILING_CONTENTErrorMore 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_DUPLICATE_KEYWarningAn 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.

Privacy

JSON Formatter & Validator runs entirely in your browser. What you type, paste or open is processed on your device: it is not sent to Toolzami, and Toolzami does not store it. Only the options you choose are remembered, in this browser.

Frequently asked questions

What is the difference between formatting and validating JSON?

Validating checks that the text follows the JSON grammar; formatting rewrites valid JSON with line breaks and indentation. This tool always does both: it validates first, and shows an output only for valid JSON.

Why does my JSON fail at a quote or a space that looks fine?

Text copied from a word processor, a chat app or a web page can carry curly quotes (“ ”) or non-breaking spaces that look like the plain ones. The error names the character and its code, such as U+201C; replace it with a straight double quote or a normal space.

Can I format a file with one JSON object per line?

Not as one document. In JSON Lines each line is a separate value, so the tool reports the second line as content after the end of the JSON. Format the lines one at a time, or wrap them in [ ] with commas between them to make one array.

How large can the JSON be?

Up to 10 MB, pasted or opened from a file. Below 1 MB the output follows your typing; for larger input, press Format. The work runs in the background, so the page stays responsive.

Last updated