Skip to content
/>codemaxxed.com

JSON formatter

Format, validate, minify or sort JSON in your browser, with exact error positions and a caret excerpt. Repair JSON5/JSONC, filter with JSONPath, convert to YAML or JSON Lines, and escape or unescape stringified JSON — nothing is sent to a server.

Runs locally. Nothing is uploaded.

JSON input

Formatted

Output appears here as you type.

Ready

How this converter works

JSON is unforgiving: one trailing comma and the whole document fails. The formatter uses a strict parser that follows the JSON grammar exactly, so if it validates here it parses in every runtime. Errors give the line and column, a plain-English cause (trailing comma, single quotes, comment, missing bracket, a no-break space pasted from a web page) and an excerpt of the line with a caret under the problem.

Pretty indents with 2 spaces, 4 spaces or tabs, optionally keeping short arrays on one line. Minify strips every byte that isn't data. Sort keys reorders objects recursively — case-sensitive, case-insensitive, natural (item2 before item10) or reversed — which makes two payloads diffable. Numbers and strings are printed exactly as written, so a 64-bit ID is never rounded; integers beyond 2^53 are flagged because JavaScript's JSON.parse would round them.

Turn on Repair invalid JSON to accept JSON5, JSONC, JavaScript object literals and Python dict output: comments, trailing commas, single or curly quotes, unquoted keys, NaN/Infinity, True/False/None, hex numbers, missing commas between lines and input truncated mid-document. Each kind of fix is listed with the position of the first one, so nothing is changed silently.

The JSONPath filter narrows big responses down: $.orders[*].id, $..email, $.items[-1], $.items[0:5] or $.items[?(@.price > 10 && @.tags)] — matches are listed with their paths. JSON Lines (NDJSON) input is read as an array, and the JSON Lines target writes one record per line. YAML converts the document to block YAML that parses the same under YAML 1.1 and 1.2. Escape turns the JSON into a string literal for embedding in code or another JSON document; Unescape reverses it, even for double-encoded strings or escaped JSON pasted without quotes. Parse JSON inside strings expands stringified payloads in place.

Everything happens locally. The input never leaves the tab, which matters when the payload contains customer records or an access token you pasted in a hurry.

Frequently asked

Does it accept comments or trailing commas?

Not by default — standard JSON doesn't allow them, and accepting them silently would hide a bug that appears the moment your API parses the same payload. The error tells you when a fix is possible; turn on Repair invalid JSON to strip comments and trailing commas (and fix JSON5 / JavaScript syntax). Every repair is reported as a warning with its position.

How are errors reported?

With the line and column of the first problem, a plain description — a trailing comma, a single-quoted string, a comment, a missing bracket, an invisible no-break space — and the offending line with a caret pointing at the exact character. The position is computed by the tool itself, so it is the same in every browser.

What JSONPath syntax is supported?

$ (root), .key and ['key'], [0] and negative indexes like [-1], [*] and .*, recursive descent ..key, unions [0,2] or ['a','b'], slices [start:end:step], .length on arrays, and filters [?(@.price < 10)] with ==, !=, <, <=, >, >=, =~ /regex/, &&, || and !. A path without wildcards returns the value itself; anything else returns an array of matches, listed with their paths below the output.

Can it handle JSON Lines / NDJSON?

Yes. Paste one JSON value per line and it is validated record by record (errors point at the right line) and treated as an array, so you can pretty-print, query or convert it. The JSON Lines target goes the other way: an array becomes one compact record per line.

What do Escape and Unescape do?

Escape turns the (minified) JSON into a single JSON string literal — "{\"a\":1}" — ready to paste into code, an environment variable or a field of another JSON document. Unescape decodes such a string back to formatted JSON. It also unwraps strings that were encoded twice and escaped JSON copied from logs without its surrounding quotes.

What happens with duplicate keys?

They are kept by default and every one is listed with its path, because most parsers silently keep only the last value. Choose Keep last to see the object exactly as JSON.parse would, or Keep first for parsers that do the opposite.

Is there a size limit?

Only your browser's memory. Files in the low megabytes format instantly; anything above roughly 20 MB will start to feel slow because the whole document is re-rendered on every keystroke.