Encoders & Utilities

JSON Formatter

Validate, format, and minify JSON with syntax highlighting.

About this tool

JSON Formatter parses any JSON document, validates it against the RFC 8259 grammar, and reformats it with consistent indentation and syntax highlighting. Paste output from an API response, a configuration file, or a log line — invalid JSON gets an inline error with the exact line and column of the parse failure; valid JSON gets pretty-printed with collapsible objects and arrays so you can navigate large structures without scrolling forever.

Beyond pretty-print, the tool can minify the JSON (strip every avoidable byte for transit), sort keys alphabetically (useful for diffing two configs), escape the whole value as a JSON-in-string (for embedding in another JSON payload), and unescape back. Everything runs locally in your browser — no payload ever crosses the network, so it is safe for API responses that contain tokens or PII.

When to use this tool

  • API debugging. Drop a curl response into the formatter to make a wall of compact JSON readable.
  • Config-file diffs. Sort both files by key, then compare — random key ordering causes noisy diffs otherwise.
  • Validation before deploy. A typo in a CI YAML often hides as malformed JSON inside a string; paste the inner JSON to confirm it parses.
  • Embedding JSON in JSON. Auto-escape a payload so it can travel as a string field in another JSON document (handy for webhook bodies in templates).

What our validator catches

RFC 8259 disallows trailing commas, comments, and unquoted keys — common JS-flavoured conveniences. We honour the spec strictly so the JSON you copy out of our formatter is valid everywhere. If you need to format JSON5 or JSONC (with comments, trailing commas), do a preliminary "strip extras" pass — many editors do this automatically when saving as .json.

Frequently asked questions

Why does my JSON with trailing commas fail to parse?

Because RFC 8259 forbids them. {"a": 1,} is valid in JavaScript but invalid JSON. The same goes for single-quoted strings, unquoted keys, and // comments — those are JS conveniences that the JSON spec deliberately excluded for cross-language portability. If you need a relaxed format, look at JSON5 or JSONC; for strict interop, our formatter is right to reject them.

Can I format JSON Lines (NDJSON)?

Not directly — NDJSON (one JSON object per line) is its own format and we treat the whole paste as a single document. To pretty-print an NDJSON file, split it into lines first and format each line individually. The result is then no longer NDJSON (since pretty-printing adds newlines), so this is for inspection only — never overwrite the original file with the pretty-printed output.

Does the tool change my keys' order?

Only if you ask. By default the formatter preserves insertion order. The "Sort keys" toggle alphabetises every object at every depth — useful for diffing two configs, but it changes the document layout. For human-friendly output that respects logical grouping, leave sorting off; for machine comparison, turn it on.

How big can the input be?

We have tested up to ~50 MB on a modern laptop. Larger than that and browser parsing slows noticeably — at 100 MB+ many browsers time out the JavaScript task. For very large JSON dumps use a streaming parser at the command line (jq, fx, jless); for the typical "API response that turned out to be 8 MB" case, the browser handles it just fine.