DEVELOPER TOOL

JSON Formatter and Validator

Paste JSON to pretty print, validate or minify it. If it is invalid, you get the exact line, column and character where it broke, and why.

Formatted or validated JSON will appear here.

About this JSON formatter and validator

This JSON formatter checks your text against the JSON standard, then pretty prints it with 2 or 4 spaces or minifies it. When the JSON is invalid, the validator gives the line, column and character where it stopped, says which rule was broken and points at it with a caret. It also warns about duplicate keys and numbers too large for JavaScript, which pass validation but change your data. Nothing you paste is uploaded.

How to use it

  1. Paste your JSON. A short sample with one mistake is loaded so you can see an error report.
  2. Click Format (2 or 4 spaces), Minify, or Validate only to check without changing anything.
  3. Fix the error at the line and column shown and run it again. Only the first error is reported, because after it the parser can't know what you meant.
  4. Copy the result.

How the error line and column are found

Formatting uses the browser's own JSON.parse() and JSON.stringify(). When parsing fails, the browser's message varies: some give a character position, some a line and column, some only quote your text, and the wording changes between engines and versions. So this page re-reads your text with its own scanner, which follows the grammar in RFC 8259 one character at a time and keeps a stack of the brackets that are still open. It stops at the first character the grammar doesn't allow. Lines are counted at every line break (LF, CRLF or a lone CR); columns count characters from 1, with a tab as one character. The browser's message is shown underneath for reference.

The position is where the JSON stopped being valid, often just after the real mistake: a missing comma is reported at the next value, and a missing closing quote at the end of its line.

Worked example

The sample in the box is:

{
  "id": 9007199254740993,
  "name": "Ana",
  "roles": ["admin", "editor",],
  "active": true
}

The page checks it as soon as it loads and reports Invalid JSON: line 4, column 31, which is the ] after "editor",. The message reads "Trailing comma: remove the comma at line 4, column 30 before ]." Delete that comma and click Format (2 spaces). The result is:

{
  "id": 9007199254740992,
  "name": "Ana",
  "roles": [
    "admin",
    "editor"
  ],
  "active": true
}

The ID changed by one, and the page warns: "Line 2, column 9: 9007199254740993 is beyond Number.MAX_SAFE_INTEGER and is written as 9007199254740992." Click Minify instead and the same data becomes one 77-character line: {"id":9007199254740992,"name":"Ana","roles":["admin","editor"],"active":true}.

JSON validator rules: what RFC 8259 doesn't allow

Most invalid JSON is valid JavaScript, or valid in a looser format such as JSON5. The validator gives a specific message for each of these common mistakes.

MistakeInvalidValid
Trailing comma[1, 2,][1, 2]
Single quotes{'name': 'Ana'}{"name": "Ana"}
Unquoted key{name: "Ana"}{"name": "Ana"}
Comment{"a": 1 // note}{"a": 1}
NaN or Infinity{"ratio": NaN}{"ratio": null}
Leading zero{"zip": 07001}{"zip": "07001"}
Plus sign, bare decimal point, hex[+1, .5, 0x1F][1, 0.5, 31]
Raw tab or line break in a stringa real tab inside "a b""a\tb"
Curly quotes from a word processor{“a”: 1}{"a": 1}

RFC 8259 says leading zeros are not allowed, that values such as Infinity and NaN are not permitted, and that the quotation mark, the backslash and the control characters U+0000 to U+001F must be escaped inside a string. Its grammar has no comment syntax. Whitespace between values can only be a space, tab, line feed or carriage return, so a no-break space pasted from a web page is an error. The standard lets parsers accept extensions, which is why some config loaders tolerate comments or trailing commas; JSON.parse() and this validator don't.

Validating vs formatting, 2 vs 4 spaces, and minifying

Validating answers one question: is this text JSON? Formatting parses the text into data and writes it back out, so the result is always valid but not a byte-for-byte copy of your input (see below). Whitespace around structural characters is insignificant, so 2-space, 4-space and minified versions parse to the same data. Two spaces keeps deep nesting from drifting right; four is easier to scan. Pick one per project. In code, JSON.stringify(data, null, 2) matches the 2-space button; per MDN, numbers above 10 are treated as 10 and "\t" indents with tabs. Minifying removes all whitespace outside strings. Note that validation checks syntax only: a missing required key needs a schema to catch.

JSON escape characters

The only escapes JSON allows. Anything else after a backslash, like \x41 or \', is an error.

EscapeMeaningNotes
\"Double quoteRequired inside a string
\\BackslashRequired inside a string
\/Forward slashOptional
\bBackspace (U+0008)Control character
\fForm feed (U+000C)Control character
\nLine feed (U+000A)Control character
\rCarriage return (U+000D)Control character
\tTab (U+0009)Control character
\uXXXXAny character by its 4 hex digit codeEmoji need two, such as \ud83d\ude00

Why formatted output can differ from your input

Common mistakes and limits

To compare two payloads by path, use JSON Diff. To convert valid JSON, try JSON to CSV or JSON to XML (and JSON vs XML on when each fits); YAML to JSON converts YAML config so you can validate it here.

Frequently asked questions

How do I find the line with the error in my JSON?

Paste the JSON and click Format or Validate. If it is invalid, the result names the line and column of the first character that breaks the JSON rules, explains which rule it broke and shows that line with a caret under the problem. The real mistake is often just before that spot, such as a missing comma at the end of the previous line.

Why does my JSON fail to validate even though it looks correct?

The most common causes are a trailing comma after the last item, single quotes instead of double quotes, unquoted object keys and comments. All of them are allowed in JavaScript code but not in JSON. Invisible characters are another cause, such as a no-break space pasted from a web page, and the validator names those by their Unicode code.

What is the difference between validating, formatting and minifying JSON?

Validating only checks whether the text is valid JSON and changes nothing. Formatting, also called pretty printing, parses the JSON and writes it back with line breaks and 2 or 4 spaces of indentation so people can read it. Minifying writes it back with no whitespace at all, which is the smallest form for sending over a network.

Does this tool support JSON with comments (JSONC)?

No. Standard JSON has no comment syntax, so the validator reports // and /* */ comments as errors. JSONC and JSON5 are separate formats that allow comments. Remove the comments first, or use a parser built for those formats.

Is my JSON data sent to a server when I use this tool?

No. Parsing, formatting and error checking all happen in your browser with JavaScript, using the built-in JSON.parse() and JSON.stringify() functions. Nothing you paste is uploaded.

Why did a long number change after I formatted my JSON?

Browsers store JSON numbers as 64-bit floating point values, which represent every integer exactly only up to 9,007,199,254,740,991, the value of Number.MAX_SAFE_INTEGER. Larger integers are rounded, so 9007199254740993 becomes 9007199254740992, and the page warns you with the line and column. Your input box is left as it was. The fix at the source is to send very large IDs as strings.

Can a JSON object have duplicate keys?

RFC 8259 says object names should be unique but does not strictly forbid duplicates, so different parsers behave differently. The browser parser used here keeps only the last value for a repeated key. This page warns you when it finds a duplicate key and shows where it is, because the formatted result silently drops the earlier value.

How do I put a line break or quote inside a JSON string?

Use an escape sequence. Write a line break as \n, a tab as \t, a double quote as \" and a backslash as \\. Typing a real line break inside the quotes makes the JSON invalid. Single quotes need no escaping in JSON, and \' is actually an error.