πŸ”

JSON Formatter & Validator

Format, validate, and beautify JSON data

Last updated

How to Use This Tool

Paste your JSON, then format it to make it readable. Copy the formatted output when you’re done.

When Should You Use This Tool?

Use this when you’re debugging APIs, reading minified JSON, or cleaning up JSON before sharing.

Steps

  1. Paste JSON input.
  2. Run format/validate.
  3. Copy the formatted JSON.

See also: Unit Converter, Coin Flip .

What does a JSON formatter and validator do?

A JSON formatter checks that your JSON is valid and prints it again with consistent indentation, so you can read nested objects and arrays at a glance. This tool parses your input with the browser's built-in JSON parser, then writes it back out with 2-space, 4-space or tab indentation (Format JSON) or with every optional space and line break removed (Minify JSON). If the input is not valid JSON, you get the parser's error message, with the line and column where possible, instead of a result, so the same button works as a validator.

How do I format or validate JSON here?

  1. Paste your JSON into the input box. Leading and trailing whitespace is ignored.
  2. Choose the Indentation: 2 spaces (the default), 4 spaces or a tab.
  3. Click Format JSON to pretty print it, or Minify JSON to compress it onto one line.
  4. If the JSON is invalid, read the error message below the buttons, go to the line and column it names, fix the mistake, and try again. Any earlier result is cleared, so Copy Result never copies stale output.
  5. Click Copy Result to copy the output.

Everything runs in your browser. Your JSON is not uploaded, which matters when it contains API keys, customer records or internal data.

What is the difference between formatted and minified JSON?

Formatted JSON adds line breaks and indentation for people, while minified JSON removes them to save bytes for machines. The data is identical. Here is one object both ways:

{"id":42,"name":"Ada","tags":["admin","editor"],"address":{"city":"London","zip":"N1"}}
{
  "id": 42,
  "name": "Ada",
  "tags": [
    "admin",
    "editor"
  ],
  "address": {
    "city": "London",
    "zip": "N1"
  }
}

Use the formatted version when reading API responses, reviewing config files or comparing two payloads in a diff. Use the minified version for request bodies, environment variables or anywhere a single line is required.

How do I know if my JSON is valid?

Your JSON is valid if Format JSON produces output. If it does not, an error message appears below the buttons, explaining what the parser expected and, when the browser reports a position, the line and column of the problem. Here the comma after "Ada" is missing:

{
  "id": 42,
  "name": "Ada"
  "admin": true
}
Invalid JSON at line 4, column 3: Expected ',' or '}' after property value in JSON at position 32

That is Chrome and Edge wording. Firefox words its messages differently but also reports the line and column, while Safari usually names the problem without a location. Lines and columns count from 1, and the character position counts from 0. The mistake is usually at or just before the reported spot: with a missing comma, the parser only complains when it reaches the next key, and with a trailing comma, when it reaches the closing brace after it.

What are the most common JSON syntax errors?

Most invalid JSON comes from copying a JavaScript object or a Python dictionary and treating it as JSON. JSON is stricter: keys and strings need double quotes, and the only literal values are true, false and null.

ErrorInvalidValid
Trailing comma{"a": 1, "b": 2,}{"a": 1, "b": 2}
Single quotes{'name': 'Ada'}{"name": "Ada"}
Unquoted keys{name: "Ada"}{"name": "Ada"}
Missing comma{"a": 1 "b": 2}{"a": 1, "b": 2}
Comments{"a": 1} // note{"a": 1}
Python values{"ok": True, "x": None}{"ok": true, "x": null}
JavaScript values{"a": undefined, "b": NaN}{"a": null, "b": null}
Unclosed bracket[1, 2[1, 2]
Raw line break in a stringA string split across two lines"line one\nline two"

Can formatting change my JSON data?

Formatting keeps your structure and values, but because the tool parses the JSON into JavaScript and serializes it again, a few details can change. These are limits of the JavaScript JSON parser, and most online formatters share them:

  • Very large integers lose precision. JavaScript numbers are 64-bit floating point, so integers above 9,007,199,254,740,991 are rounded: 12345678901234567890 becomes 12345678901234567000. Check 64-bit IDs before you copy the output.
  • Duplicate keys collapse. {"a": 1, "a": 2} becomes {"a": 2}, because the last value wins.
  • Number notation is normalized. 1.0 becomes 1 and 1e3 becomes 1000.
  • Unicode escapes are decoded. "Γ©" is printed as "Γ©".
  • Integer-like keys move first. Keys such as "1" and "2" are listed before other keys in ascending order. All other keys keep their original order.

How do I format JSON from the command line or in code?

These commands produce the same kind of output as this tool, which is handy for scripts and large files:

# jq (2-space indent by default)
jq . data.json
jq --indent 4 . data.json
jq --tab . data.json

# Python (4-space indent by default)
python -m json.tool --indent 2 data.json
python -m json.tool --tab data.json

// JavaScript
JSON.stringify(JSON.parse(text), null, 2)      // 2 spaces
JSON.stringify(JSON.parse(text), null, 4)      // 4 spaces
JSON.stringify(JSON.parse(text), null, '\t')   // tab
JSON.stringify(JSON.parse(text))               // minified

Frequently Asked Questions

What if my JSON is invalid?
The tool shows the parser's error message below the buttons instead of a result, with the line and column of the problem when the browser reports a position, as Chrome, Edge and Firefox do. Common causes are trailing commas, single quotes, unquoted keys, missing commas and unclosed brackets.
Does formatting change the data?
Formatting and minifying only change whitespace for normal JSON. The exceptions come from the JavaScript parser: integers larger than 9,007,199,254,740,991 are rounded, duplicate keys keep only the last value, and numbers like 1.0 are written as 1.
Can I format very large JSON files?
The tool handles typical API responses and config files easily. Files of several megabytes can make the browser tab slow because the whole result is displayed at once. For those, use jq or python -m json.tool on the command line.
What's the difference between format and minify?
Format adds line breaks and indentation for readability, using 2 spaces, 4 spaces or a tab as you choose. Minify removes all optional whitespace and puts the JSON on one line, which makes it smaller for sending over a network or storing in a single-line field.
Does it handle JSON with comments?
No. Standard JSON does not allow comments, and neither does this tool, so // or /* */ comments cause a parsing error. The same applies to JSON5 and JSONC features such as trailing commas and single quotes. Remove them before formatting.
Can I change the indentation to 4 spaces or tabs?
Yes. Pick 2 spaces, 4 spaces or Tab in the Indentation menu before clicking Format JSON. The default is 2 spaces. Minify ignores this setting because it removes all indentation.
Why did a long number change after formatting?
JavaScript stores numbers as 64-bit floating point, which can only represent integers exactly up to 9,007,199,254,740,991. Larger integers, such as some database or social media IDs, are rounded when parsed. APIs often send these IDs as strings to avoid the problem.
Is a single value like 42 or "hello" valid JSON?
Yes. Since RFC 8259, a JSON document can be any single value, including a number, a string, true, false or null, not only an object or array. This tool accepts and formats them.