JSON Formatter & Validator

Format, validate and minify JSON instantly. Your data never leaves your browser.

Updated:

100% client-side

Input

0 characters

Output


        
—

What is JSON?

JSON (JavaScript Object Notation) is the plain-text format most APIs, config files and web apps use to exchange structured data — nested key-value pairs, lists and text, without any binary format or schema required. It's standardized in RFC 8259. When JSON comes back from an API compressed onto a single line, or has a typo that breaks it, this tool re-indents it for readability, tells you exactly where a syntax error is, and can shrink it back down (minify) for production use.

How to use JSON Formatter

  1. Paste your JSON into the Input panel, or click Paste / Example.
  2. Any syntax error is flagged immediately with the exact line and column.
  3. Pick 2 sp., 4 sp. or Minified above the Output panel to control the output style.
  4. Click Copy or Download to grab the formatted result.

How JSON formatting works

JSON (JavaScript Object Notation) organizes data as nested key-value pairs. A formatter takes compact JSON — with no line breaks or indentation — and rewrites it with a clear visual hierarchy, so it's easy to read and debug:

// Before
{"user":{"id":42,"name":"Ada","roles":["admin","dev"]}}

// After (2 spaces)
{
  "user": {
    "id": 42,
    "name": "Ada",
    "roles": ["admin", "dev"]
  }
}

This tool uses the browser's native JSON.parse to validate the structure and JSON.stringify to reformat it — both implement the grammar defined in RFC 8259, so parsing behavior (rejecting trailing commas, requiring double-quoted keys, etc.) matches the spec exactly, not a looser JSON5/JSONC dialect. No external libraries, no server calls.

Examples

1. Read a minified API response. Most APIs return JSON on a single line to save bytes. Pasted as-is, this order response becomes readable with 2-space indentation:

// Input
{"id":1042,"status":"shipped","items":[{"sku":"A-17","qty":2},{"sku":"B-03","qty":1}],"total":59.9}

// Output (2 sp.)
{
  "id": 1042,
  "status": "shipped",
  "items": [
    {
      "sku": "A-17",
      "qty": 2
    },
    {
      "sku": "B-03",
      "qty": 1
    }
  ],
  "total": 59.9
}

2. Minify a config before shipping it. Choose Minified and every space and line break outside strings is removed — useful for embedding JSON in an environment variable or a URL parameter:

// Input
{
  "debug": false,
  "port": 8080,
  "hosts": ["a.local", "b.local"]
}

// Output (Minified, 57 characters)
{"debug":false,"port":8080,"hosts":["a.local","b.local"]}

3. Format a log file in NDJSON. Logging libraries often write one JSON object per line. Instead of rejecting the whole input, the formatter treats each line as its own document and reports 2 valid JSON documents (NDJSON):

// Input
{"level":"info","msg":"started"}
{"level":"error","msg":"timeout","ms":3000}

// Output
{
  "level": "info",
  "msg": "started"
}

{
  "level": "error",
  "msg": "timeout",
  "ms": 3000
}

Common JSON errors and how to fix them

Strict JSON is less forgiving than a JavaScript object literal. These are the mistakes that cause almost every "invalid JSON" message. The error texts below are the ones Chrome shows; Firefox and Safari word them differently but point to the same spot.

  • Trailing comma. {"name": "Ada", "roles": ["admin"],} — a comma after the last item is legal in JavaScript but not in JSON. Chrome reports Expected double-quoted property name … (line 4, column 1), pointing at the closing brace right after the stray comma. Delete the comma.
  • Single quotes. {'name': 'Ada'} — JSON strings and keys must use double quotes. The error lands on line 1, column 2, the first quote. Replace every ' with " (watch for apostrophes inside the text).
  • Unquoted keys. {name: "Ada"} works in JavaScript, not in JSON. Wrap each key in double quotes: {"name": "Ada"}.
  • NaN, Infinity and undefined. They are not JSON values. Use null, a string, or a sentinel number; if the data comes from JSON.stringify, note it already turns NaN into null and drops undefined keys.
  • Invisible byte-order mark (BOM). Files saved as "UTF-8 with BOM" (common in Windows editors) start with the invisible character U+FEFF, and the error message points at a character you can't see. Re-save the file as plain UTF-8, or delete the first character of the input.

If your file uses comments or trailing commas on purpose, it is JSON5 or JSONC (the format of VS Code's settings.json), not JSON — this tool deliberately follows the strict RFC 8259 grammar, the one every API parser enforces.

JSON Formatter vs. command-line alternatives

If the JSON is already a file on a machine with a terminal, the command line is faster: jq . data.json pretty-prints it, jq -c . data.json minifies it, and python -m json.tool data.json works anywhere Python is installed. This page is the better choice when the JSON is on your clipboard (a response copied from browser devtools, a payload from a log viewer), when you are on a machine where you can't install anything, or when you want the error's exact line and column instead of a stack trace. Once the JSON is valid, the JSON Tree Viewer lets you fold large documents, the JSON Diff compares two versions key by key, and JSON to Types turns a sample into TypeScript interfaces.

Frequently asked questions

Is it safe to paste sensitive data here?

Yes. All processing happens in your browser using native JavaScript; no data is ever sent to a server.

Does it support large JSON files?

It handles most typical JSON files well. Extremely large documents (several MB) can get slow because formatting runs on the main thread.

Does it detect syntax errors?

Yes, it shows the exact line and column where the JSON stops being valid, as soon as you stop typing.

Can I paste multiple JSON documents in a row (NDJSON)?

Yes. If you paste several JSON documents one after another (separated by whitespace or a newline), each one is validated and formatted separately instead of the whole input being marked invalid.