JSON Formatter

Converter

Beautify, minify and validate JSON data with syntax error detection. Catch malformed brackets and commas before they break your API integration or build.

Ready
Input
0 lines·0 B
Output
0 lines·0 B

About JSON Formatter

JSON copied out of an API log, a database text column or the browser console usually arrives as one endless line. So you cannot see the hierarchy and end up hunting brackets to work out which level a field belongs to. A formatter solves exactly that: paste the raw text and get an indented structure immediately, then minify it back to a single line when you need to paste it into code or config. The mechanism is straightforward: JSON.parse performs a strict parse, then JSON.stringify re-emits the value with the indentation you choose, entirely inside the browser. It deliberately performs no "auto repair", because lenient fixing hides real syntax errors and makes you trip over them somewhere else later. A few practical points. Whether you pick 2 or 4 space indentation affects readability only, never validity. If the goal is to compare two configs, sort object keys before diffing, otherwise the same config written differently lights up as a large change. After formatting, minify again before pasting into source files so you do not drag hundreds of indented lines into your repository. Know the limits: The JSON specification allows no comments, no trailing commas, no single-quoted strings, and no NaN or Infinity literals, yet content copied from a JavaScript object literal usually carries all four, and the parser answers with an Unexpected token error. That message carries no line number, so the practical method is to minify first and shrink the input section by section. The other frequent trap is precision: integers above 2^53 - 1 (snowflake IDs, nanosecond timestamps) cannot be represented exactly as JS numbers, and after formatting the last digits silently become zeros. Ask the API to return such fields as strings. Finally, multi-megabyte documents stall the browser or trigger memory warnings; split huge files by top-level key on the command line first. Data and privacy: API responses routinely carry access tokens, phone numbers, internal hostnames and user IDs, so uploading them to a third-party formatter is a disclosure. This tool parses and serializes locally and issues no network requests. Open the Network panel, paste a sensitive value and confirm nothing is sent, or simply disconnect the network and try again. The boundaries with neighbouring scenarios are worth spelling out. Config files with comments (JSONC, JSON5) are rejected by a strict parser even though editors and some build tools accept them by default, which produces the "fine locally, fails in CI" gap. The fix is to adopt a format that supports comments such as YAML or TOML, or to strip comments at build time before publishing. Another common shortcut is parsing configuration with eval or new Function, which turns a data file into executable code and makes tampering equivalent to arbitrary code execution, so avoid it entirely. When you need to consult the structure repeatedly, save the formatted output to a file and use your editor's folding instead of re-pasting it into a web tool every time. One last workflow suggestion: wire formatting into your editor's save action or a pre-commit check so you stop round-tripping through a web tool, and make "format first. Then diff" part of your debugging checklist to cut the time spent on configuration problems. Note also that the character count should be unchanged by formatting: if it drops noticeably the original was truncated, so confirm the copy first before hunting syntax errors.

How It Works Internally

Formatting does two things only: parse the text strictly into an in-memory tree, then serialise it again with the indentation you choose. Strictness is the point — the parser will not add missing quotes or drop a trailing comma, so syntax errors surface immediately instead of being silently repaired and resurfacing elsewhere. Indent width affects readability alone and takes no part in validity.

Minified input to 2-space indent
Input{"b":2,"a":[1,{"c":true}]}
Output{ "b": 2, "a": [ 1, { "c": true } ] }

Measured on This Page

Fixed: big integers rewrittenThe old pipeline ran JSON.parse, which stores integers as IEEE-754 doubles: 9007199254740993 became 9007199254740992, silently rewriting order numbers and snowflake IDs. Big integer literals are now swapped for sentinel strings before parsing and restored after serialisation
5/5 semantic equalityCJK with nesting, floats and exponents (1e21, -0.5), nested arrays [[1,2],[3,[4]]] and escaped quotes/newlines all re-parse to exactly the source object
Invalid inputA trailing comma {"a":1,} reports an error with a position instead of emitting half a result
Output viewsTree view by default with a code view toggle; the code view text matches the input semantically

The damage a JSON formatter most easily does is to numbers: JSON.parse stores integers as IEEE-754 doubles, so anything past 2^53-1 (9007199254740991) loses its last digit — and that digit is usually the meaningful part of a distributed ID, order number or snowflake ID, so the copied request finds nothing. The fix swaps out-of-range integer literals for sentinel strings before parsing and restores them afterwards (cost: such numbers appear as strings inside JSONPath queries). The other classic trap is key order — formatting should not reorder keys; use the sort feature when stable output matters.

How this was measured: Five JSON documents (CJK with nesting, an integer beyond 2^53, floats with exponents, nested arrays, escaped characters) were pasted in and the output re-parsed with Python json and compared field by field; invalid JSON was also exercised. Measured before and after the fix. · Measured 2026-10-31

How to Use

  1. Open the JSON Formatter tool
  2. Paste or type your JSON data in the left editor
  3. Click 'Beautify' to format the JSON or 'Minify' to compress it
  4. Review the structured data with syntax highlighting and line numbers
  5. Copy the formatted JSON or download it as a file

Use Cases

  • Debug API responses — Pretty-print flat backend JSON into a highlighted, readable structure; on errors it pinpoints the exact line and column.
  • Extract with JSONPath — Use expressions like $.data.users[0].name to filter output in real time and pull target data from large responses.
  • Validate config files — Check syntax of package.json, tsconfig.json and other configs with error-line highlighting before deployment.
  • Reduce transfer size — Minify formatted JSON into a single line to reduce network payload — typically 20-50% smaller.
  • Sort and escape — Sort keys with one click for easier diffing, or JSON-escape/unescape string content.
  • Share data snippets — Compress the current JSON into a share URL — no server upload, just send the link to a colleague.
  • Schema comparison — Format two JSON objects side by side to quickly spot structural differences in API responses or config files.
  • Large file inspection — Collapse deeply nested nodes in the tree view to navigate massive JSON responses without scrolling endlessly.

FAQ

Can it pinpoint the error line?

Yes. On a parse failure the editor highlights the offending line and shows "line X, column Y" with a plain-language hint (missing comma, unquoted property, etc.), so no manual character hunting.

How do JSONPath queries work?

Type an expression like $.config.theme or $.tags[*] in the query bar; the output shows matches and a hit count in real time, with wildcards, recursive descent and filter expressions.

How large a JSON can it handle?

Built on the CodeMirror editor, it edits multi-MB JSON smoothly. For log-sized files, pre-process with a command-line tool like jq first.

Does it support JSON5 / JSONC?

No. This tool only handles strict JSON. For comments or single-quoted syntax, convert to standard JSON first.

Does the share link upload my data?

No. Sharing LZ-compresses the data into the URL hash fragment, so the data stays in the link itself and never hits a server.

How do I convert to YAML or TOML?

Use our Data Format Converter or the JSON to YAML / JSON to TOML tools for lossless multi-format conversion.

Why does my Chinese text turn into \uXXXX escape sequences?

It is display output caused by serializing with ASCII-only escaping, not data corruption — the underlying characters are intact. Turn off the "escape non-ASCII" option (or pick non-escaping output) and Chinese is preserved as-is. If exported text already contains \uXXXX, feed it to our Unicode Escape tool to restore readable characters.

Does formatting change the JSON content?

No — only whitespace and indentation change; keys, order and numeric precision are preserved. Watch out for very large numbers (18-digit order IDs): JavaScript's Number loses precision above 2^53 at parse time, which is unrelated to formatting and needs strings or BigInt.