FlexUtil
📋

JSON Formatter & Validator

Prettify, minify, and validate JSON with syntax error highlighting.

By Sergei Selivanov Last updated

JSON (JavaScript Object Notation, standardised as RFC 8259 and ECMA-404) is the data format that the modern web runs on. Almost every REST API, every package.json, every configuration file in a node/cloud toolchain is JSON. It is trivial for machines to read, but the “minified” JSON that servers actually send — a single line with no whitespace — is nearly unreadable for humans. This tool reformats any JSON to a cleanly indented form, validates it against the strict grammar, highlights the exact position of any syntax error, and can re-minify it for production. Everything runs in your browser, so API responses containing secrets or customer data never leave your machine.

What “prettifying” does

Prettifying adds indentation, line breaks, and spacing so the nested structure becomes visible at a glance.

Before (minified):

{"user":{"id":1,"name":"John Doe","email":"john@example.com","roles":["admin","editor"],"active":true}}

After (prettified):

{
  "user": {
    "id": 1,
    "name": "John Doe",
    "email": "john@example.com",
    "roles": [
      "admin",
      "editor"
    ],
    "active": true
  }
}

Semantically the two are identical. A JSON parser treats whitespace between tokens as meaningless, so you can round-trip between minified and pretty versions freely.

What validation catches

The tool parses your input with the browser’s native JSON.parse, so any input that passes the tool will also parse cleanly in Node.js, Python, Go, Rust, Java, or any other modern runtime using a standards-conformant parser. When parsing fails, the tool reports the line and column of the first violation and highlights the character.

Common errors it surfaces:

  • Trailing commas. [1, 2, 3,] is invalid JSON, even though JavaScript arrays accept it. This is the single most frequent cause of “invalid JSON” errors.
  • Single quotes. {'name': 'John'} is not JSON — keys and string values must use double quotes.
  • Unquoted keys. {name: "John"} is a JavaScript object literal, not JSON. All keys must be quoted strings.
  • Unescaped control characters in strings. A literal tab or newline inside a string must be written as \t or \n.
  • Mismatched brackets. Every { needs a matching } and every [ needs a matching ].
  • Comments. JSON does not support // or /* */ comments. If your input has them, you are probably looking at JSON5 or JSONC (see below).
  • Invalid literals. JavaScript undefined, NaN, Infinity, and bare identifiers are not valid JSON values.
  • Duplicate keys. The spec technically allows them but discourages them; most parsers keep only the last value.

JSON vs. JSON5, JSONC, and YAML

Several “JSON-like” formats relax the strict rules to make hand-written configs nicer. They are not interchangeable with strict JSON:

  • JSONC — JSON with Comments. Used by VS Code’s settings.json and tsconfig.json. Strip the comments before feeding to a strict parser.
  • JSON5 — JSON with comments, trailing commas, single quotes, unquoted keys, hex numbers, and a few more niceties. Common in Babel and Rollup configs.
  • YAML — a superset of JSON in theory, with indentation-based syntax. Most docker-compose.yml, k8s manifests, and GitHub Actions files. Not accepted by JSON.parse.

If you’re pasting something into this tool and it rejects it with a comment error, you probably have JSONC. Strip the comments first, or use a JSONC-aware parser upstream.

How to use this tool

  1. Paste your JSON into the editor.
  2. Auto-format runs as you type; the pretty version appears alongside the input.
  3. Minify button collapses it back into a single line for copy-paste into a curl command or a URL-safe body.
  4. Copy grabs either the pretty or the minified output.
  5. Errors appear inline with line and column, so you can fix invalid input immediately.

Worked example: a subtle escaping error

You pasted an API response and got “Unexpected token in JSON at position 42.” The payload looks like:

{"message": "User said "hello" to the server"}

The issue is that the embedded "hello" is closing the outer string prematurely. The fix is to escape the inner quotes:

{"message": "User said \"hello\" to the server"}

Alternatively, the producer can escape with single quotes inside a JavaScript template, but on the wire, backslash-escape is the only correct approach.

Minifying: when and why

Minified JSON saves bytes in network payloads. The savings are usually around 10–20% for typical API responses (keys are not abbreviated, just whitespace is removed). For API responses, servers generally minify in production; for config files that humans will edit, always store the pretty version. Never commit minified JSON to a source repo — the diff noise on any change is brutal.

Compression (gzip, brotli) does much more than minification: a gzipped pretty JSON response is typically 5–10% larger than a gzipped minified one, because gzip handles repeated whitespace almost for free. If your transport is compressed, minification is mostly cosmetic.

Schema validation

This tool validates syntax (is it valid JSON?) not semantics (does it match my expected shape?). For semantic validation, use a JSON Schema library such as:

  • ajv (JavaScript/TypeScript)
  • jsonschema (Python)
  • gojsonschema (Go)
  • justify-schema or json-schema-ref-parser (language-agnostic)

A JSON Schema describes required fields, types, enums, and ranges. Schema-level validation is what API gateways, form builders, and OpenAPI/Swagger toolchains rely on.

Frequently asked questions

Is my JSON sent to your servers?

No. The tool runs entirely in the browser using the native JSON.parse and JSON.stringify. Neither your input nor the formatted output is transmitted.

What’s the maximum size I can paste?

Limited only by your browser’s memory. Tens of megabytes work on a typical laptop; hundreds of megabytes may freeze the UI during parsing. For very large payloads, use a streaming parser (jq, simdjson, ijson) offline.

Can it format JSON embedded in another file?

No — this tool expects standalone JSON. If you have JSON inside a JavaScript file or a log line, extract it first (copy between the outermost { or [ and its matching closer).

Why does my file work in Chrome but not in this tool?

Chrome’s DevTools sometimes display invalid JSON as if it were valid (for example, stripping comments or trailing commas for readability). If this tool flags an error, a strict parser on the server will also flag it — the tool is giving you the more useful answer.

How do I fix “Unexpected token” errors?

Check the line and column shown. Most of the time the problem is earlier than you’d expect: a missing comma on a previous line, a stray trailing comma inside an object, or an unescaped quote inside a string. Working backwards from the reported position usually finds the cause within a few lines.

Privacy note

Formatting, validation, and minification happen entirely in your browser. JSON you paste here never leaves your device — safe for API responses, config files, and payloads containing personal data.