JSON Formatter

Format, minify, and validate JSON

Loading tool…

About JSON Formatter & Validator

JSON Formatter & Validator re-indents a JSON document so its structure is visible, collapses it back to a single line when you need a compact payload, and reports the exact position of the first syntax error when the input cannot be parsed.

JSON has a much smaller grammar than most people assume. There are no comments, no trailing commas, no single-quoted strings, and no unquoted keys — those are JavaScript object-literal features that JSON deliberately left out. Most "invalid JSON" reports come from a document that a JavaScript engine would happily accept, which is why the error position matters more than the error message.

How to use this developer tool

  1. Paste the response body, configuration file, or log line into the input area.
  2. Choose Format to pretty-print with indentation, or Minify to strip every optional space and newline.
  3. If parsing fails, read the reported offset and inspect the few characters immediately before it rather than the line the message names.
  4. Compare the formatted output against the original to confirm no value was reinterpreted, especially long integers and numbers with leading zeros.
  5. Copy the result, or keep the formatted copy for review and ship the minified one.

Worked example: finding a trailing comma

This payload looks fine at a glance and is accepted by a JavaScript console, but a strict JSON parser rejects it. The formatter reports the position of the first character that cannot begin a value.

Input
{"id":42,"tags":["beta","internal",],"owner":{"name":"Ada","email":"ada@example.com"}}
Reported error
Unexpected token ] in JSON at position 35

Position 35 is the closing bracket, but the defect is the comma at position 34. A parser can only report where a value was expected, never where the extra separator was typed, so always look one character back.

What JSON does and does not allow

Every row on the right-hand side is valid JavaScript and invalid JSON. This table resolves most parse failures on its own.

ConstructValid JSONCommon invalid form
Object keys{"name": "Ada"}{name: "Ada"}
Strings"single item"'single item'
Trailing separators[1, 2, 3][1, 2, 3,]
Commentsnot supported at all{"a": 1} // note
Numbers{"n": 0.5}{"n": .5} or {"n": 007}
Special values{"v": null}{"v": undefined} or {"v": NaN}

Troubleshooting

A large numeric ID changes value after formatting.

Why it happens JSON numbers are parsed as IEEE 754 doubles. Integers above 2^53 - 1 lose precision, so a 19-digit Snowflake or database ID is silently rounded.

Fix Ask the producing service to serialize the identifier as a string. If you only need to read the document, inspect the raw text instead of the parsed result.

The error message names a line far below the real mistake.

Why it happens A missing closing brace or an unterminated string lets the parser keep consuming input until something structurally impossible appears.

Fix Format the document down to the last line that renders correctly, then examine the block that follows it. Unbalanced quotes usually show up as a very long highlighted string.

A log line will not parse even though it looks like JSON.

Why it happens Log shippers frequently prefix a timestamp and level, or escape the entire document so that it arrives as one JSON string containing JSON.

Fix Remove any prefix before the first brace. If the whole payload is wrapped in quotes with backslash escapes, decode that string once and format the result.

Minified output is larger than expected.

Why it happens Minification only removes insignificant whitespace. Long key names, repeated structures, and Base64 blobs dominate the size of most documents.

Fix Use HTTP compression for transport. Minify for a request body or fixture, not as a size-reduction strategy.

When this tool is the right choice

  • Making an API response readable while you debug an integration.
  • Confirming that a configuration file is syntactically valid before a deploy rejects it.
  • Producing a compact single-line body for a curl command or a test fixture.
  • Locating the exact offset of a syntax error that a server log only described as "malformed request".

When to use something else

  • Checking that a document matches an expected shape. Formatting proves syntax only; use JSON Schema validation for required fields and types.
  • Querying or extracting values from a large document. The JSONPath Tester is built for that.
  • Reformatting JSON Lines or NDJSON files, where each line is a separate document rather than one array.

Privacy and data handling

Parsing and re-serialization happen in this browser tab using the platform JSON implementation. The document is not sent to a server, is not stored between visits, and is discarded when you close the tab. Access tokens embedded in a sample response are still visible to browser extensions and to anyone looking at your screen, so redact them before pasting.

Related developer tools

Frequently asked questions

Does formatting change my data?

Formatting only changes whitespace between tokens, so keys, strings, and booleans round-trip exactly. The one exception is numeric precision: integers beyond 2^53 - 1 and numbers with more significant digits than a double can hold are re-serialized at the nearest representable value.

Why is my JSON with comments rejected?

The JSON specification has no comment syntax. Formats that allow them, such as JSONC in editor configuration or JSON5, are separate languages. Strip comments before parsing, or use the loader that understands the dialect your tool expects.

Is minified JSON faster to parse?

Marginally, and almost never enough to measure. Whitespace is skipped by the tokenizer very cheaply. Minification mostly helps by reducing bytes on the wire, which HTTP compression already does more effectively.

Can I format a file that is tens of megabytes?

Very large documents are limited by browser memory, since the whole structure must be held at once. For files above roughly a hundred megabytes use a streaming command-line tool instead of any browser-based formatter.

Does the tool preserve the order of object keys?

Yes. Key order is preserved as written because the output is produced from the parsed structure in insertion order. The JSON specification does not guarantee that consumers respect order, so do not rely on it for correctness.

What is the difference between valid and correct JSON?

Valid JSON parses. Correct JSON also carries the fields and types the receiving system expects. A document can be perfectly valid and still be rejected by an API because a required property is missing or a number arrived as a string.