JSON Formatter

Format, validate and query JSON, with parse errors that point to the exact line and column.

e.g. $.data.items[0].id

Tree view

Everything here runs on your device. Nothing you enter is uploaded or stored.

Paste JSON and get it formatted with adjustable indentation, minified to one line, explored in a collapsible tree, or queried with a JSONPath expression — with parse errors resolved to an exact line and column rather than a raw character offset.

How to use it

  1. Paste your JSON into the input box.
  2. Choose format or minify mode, and set the indent width if formatting.
  3. If the JSON is invalid, the exact line and column of the error is shown.
  4. Use the collapsible tree view to explore nested objects and arrays without scrolling through raw text.
  5. Enter a JSONPath expression like $.data.items[0].id to pull out a specific value.

The error message JSON.parse doesn’t give you

JSON.parse throws an error the moment it hits invalid syntax, and the error message is just a string: something like Unexpected token } in JSON at position 42. That position is a raw character offset into the whole input — genuinely useful information, but useless to a human staring at a 40-line pasted document, because nobody can count 42 characters by eye.

This tool walks the source text up to that offset, counting newlines along the way, and converts the raw position into a 1-based line and column number — the same coordinates your text editor uses. Paste a broken config file and instead of “position 4271,” you get “line 87, column 14,” which you can jump to directly.

Why some errors have no location, and that’s honest, not broken

There’s no universal standard for how JavaScript engines report parse error locations. Recent V8 — the engine behind current Chrome and Node 20+ — includes a position for most structural errors like a missing comma or an unexpected character. But certain error types, most commonly “Unexpected end of JSON input,” carry no location in any engine, because the parser has run out of text and genuinely cannot say where the document should have continued — there’s no position to report.

Firefox’s SpiderMonkey and Safari’s JavaScriptCore format their error messages differently from V8 again, using different sentence structures for line and column. This tool tries several known patterns across engines, and when none match, it shows the raw error message without inventing a location. A guessed location that’s wrong is worse than an honest “no location available.”

JSONPath-lite: enough to be useful, not enough to be dangerous

Full JSONPath ($..deep.wildcard[?(@.filter)]) is a large specification with filters, wildcards, and recursive descent — powerful, but also a much bigger surface to implement correctly and securely for a client-side tool. This formatter supports a deliberately smaller subset: dot notation ($.a.b), bracket array indexing ([0]), and quoted bracket keys for property names with special characters (["a-b"]). That covers the overwhelming majority of “find this one value in a big response” use cases without the complexity of a full JSONPath engine.

What it does not do

It does not validate against a JSON Schema — for that, see the JSON Validator. It formats and queries only; it does not diff two JSON documents against each other. The JSONPath support is intentionally partial, not a full implementation of the specification.

Common JSON.parse errors and what they mean

Error message fragmentLikely cause
Unexpected token }Trailing comma before a closing brace
Unexpected end of JSON inputA closing brace, bracket, or quote is missing
Unexpected token in JSON at position NOften a stray comma, or unquoted key
Unexpected non-whitespace character after JSONExtra content after a complete, valid JSON value

JSONPath-lite syntax

SyntaxMeaning
$The whole document
$.keyA top-level property
$.a.b.cNested properties
$.items[0]First element of an array
$["key-with-dash"]A key with characters dot notation can’t express

Questions

Why does the error location matter so much?

JSON.parse's native error message is a plain string like "Unexpected token } in JSON at position 42" — a character offset baked into English text, not a structured field. Finding position 42 in a large pasted document by counting characters by hand is slow. This tool walks the source up to that offset and converts it into a line and column number instead, so you can find the problem directly in a text editor.

Why do some errors have no location at all?

There is no single stable error format across JavaScript engines. Recent V8 (current Chrome, Node 20+) gives a position for most structural errors, but messages like "Unexpected end of JSON input" carry no location in any engine — the parser genuinely doesn't know where the document should have continued. Firefox and Safari also format their error messages differently from V8. When no location can be extracted, the message is still shown; only the position is honestly omitted rather than guessed.

What is JSONPath-lite?

A small, safe subset of full JSONPath syntax supporting dot notation, bracket indexing, and quoted keys — $.a.b[0]["c-d"] — enough to pull a nested value out of a large document quickly. It does not support the full JSONPath specification's wildcards, filters, or recursive descent.

Is my JSON sent anywhere?

No. Parsing, formatting, and querying all run in your browser using the native JSON.parse and JSON.stringify. Nothing is transmitted, which matters for JSON containing API responses, config files, or anything else you'd rather not paste into a random web form.

Last updated