Quick answer: To format and validate JSON, paste it into a JSON formatter that parses it with a strict parser. If the JSON is valid, you get a cleanly indented copy; if it is not, you get an error that points to the problem so you can fix it.

Try the free JSON Formatter & Validator

Free, no sign-up, and built by the author of this guide.

Open the JSON Formatter & Validator

What valid JSON looks like

JSON is defined by two matching standards: RFC 8259 and ECMA-404. Both describe a small grammar with six kinds of value:

  • Objects in curly braces, with "name": value pairs separated by commas.
  • Arrays in square brackets, with values separated by commas.
  • Strings in double quotes, with special characters escaped, such as \" and \n.
  • Numbers in decimal form, such as 42, -3.5 or 1e6.
  • The literals true, false and null, in lowercase.

Whitespace between values is ignored, which is why the same data can be pretty-printed for people or minified for machines. RFC 8259 also says JSON exchanged between systems must be encoded in UTF-8.

Formatting versus validating

Validating means checking that text follows the JSON grammar. A strict parser either accepts the whole document or stops at the first error.

Formatting, also called pretty-printing, rewrites valid JSON with line breaks and indentation so nested objects are easy to read. Minifying does the opposite and removes all unnecessary whitespace, which makes files and API payloads smaller.

Formatting always depends on validation: a tool cannot reliably indent data it cannot parse. Note that validation only checks syntax. It does not check whether required fields are present or values have the right types; that needs a schema check.

How to use the free JSON Formatter & Validator

The tool parses your input with the browser's built-in JSON.parse, so the data stays on your device.

  1. Open the JSON Formatter & Validator.
  2. Paste your data into the JSON box.
  3. Click Format & validate. If the data is valid, the tool shows Formatted JSON indented with two spaces.
  4. If the data is not valid, the tool shows Invalid JSON and the parser's error message. The wording comes from your browser, so it differs between Chrome, Firefox and Safari, but it usually names the unexpected character or its position.
  5. To shrink valid JSON to one line, click Minify. The result appears under Minified JSON.
  6. Click Copy result to copy the output to your clipboard.

Worked example: format, minify and fix

Paste this minified API response:

{"id":42,"name":"Ada","roles":["admin","dev"],"active":true}

Click Format & validate and you get:

{
  "id": 42,
  "name": "Ada",
  "roles": [
    "admin",
    "dev"
  ],
  "active": true
}

Clicking Minify on that output returns the original single line.

Now try this hand-edited version:

{'id': 42, "roles": ["admin", "dev",],}

The tool reports Invalid JSON. There are three problems: the name 'id' uses single quotes, and there are trailing commas after "dev" and after the closing bracket. The parser stops at the first one, so fix it, click again and repeat until the data is valid: {"id": 42, "roles": ["admin", "dev"]}.

Pretty-print or minify?

Use formatted JSON whenever people read or edit the data: configuration files, documentation, code reviews and debugging. Indentation makes nesting visible, and line-by-line diffs in version control become meaningful.

Use minified JSON when only machines read it, such as API responses and data embedded in web pages, where every byte is transferred. If the server already compresses responses with gzip or Brotli, the saving from minifying is smaller, but it still helps.

On the command line, python3 -m json.tool file.json and jq . file.json validate and pretty-print a file, which is useful in scripts and build pipelines.

Common mistakes

  • Trailing commas. JavaScript allows [1, 2,]; JSON does not.
  • Single quotes. Strings and names must use double quotes.
  • Comments. // and /* */ comments are not part of JSON. Some tools accept them in config files, but strict parsers reject them.
  • Unquoted names. {id: 42} is a JavaScript object literal, not JSON.
  • JavaScript-only values. undefined, NaN, Infinity and numbers with leading zeros such as 007 are invalid.
  • Raw line breaks inside strings. Use \n instead of pressing Enter inside a string.
  • Very large integers. Browsers read JSON numbers as 64-bit floating point, so 9007199254740993 is reformatted as 9007199254740992. Keep long IDs as strings.
  • Duplicate names. RFC 8259 says names should be unique. With duplicates, JSON.parse keeps only the last value, so the formatted output silently drops the earlier one.

Frequently asked questions

What is the difference between JSON and a JavaScript object?+

JSON is a text format with stricter rules: names must be double-quoted strings, and comments, trailing commas, functions and undefined are not allowed. A JavaScript object literal is code and allows all of those.

Why does my JSON fail with an unexpected token error?+

The parser found a character it did not expect at that point. The usual causes are a trailing comma, a single quote, a comment, a missing comma between values or a missing closing bracket.

Does formatting change my data?+

The values stay the same, but the tool rebuilds the text from the parsed data. Numbers are normalized (1.0 becomes 1), integers above 2^53 lose precision and duplicate names keep only the last value.

Can JSON contain comments?+

No. RFC 8259 and ECMA-404 have no comment syntax. Formats such as JSONC and JSON5 add comments, but they are separate formats that strict JSON parsers reject.

Is my JSON uploaded anywhere?+

No. The tool parses and formats the data with JavaScript in your browser and does not send it to a server.

Try the free JSON Formatter & Validator

Put this guide into practice in your browser.

Open the JSON Formatter & Validator