Guide · JSON & Data

How to Fix Invalid JSON (Commas, Quotes, and Trailing Junk)

Updated 2026-08-07 · 4 min read

Unexpected token is usually not a mysterious codec problem. It is a trailing comma, a single-quoted key, a comment, a truncated network copy, or HTTP headers still sitting above the body. Fix the text. Then format it.

JSON Formatter on DevOkk.com is the place to see the error and retry. The paste stays in the browser. No account. If the broken payload might contain tokens or PII, do not throw it at a random “JSON repair” upload. Browser-local is the safer default. Auto-repair tools that guess are how fields disappear.

Why invalid JSON is usually a paste

You copy from Chrome’s network panel and miss the last }. You copy from a test file that is a JavaScript object. You copy from a log line that has a prefix: INFO payload=. You copy two responses. You copy HTML that happens to include a {.

The formatter’s job is to say no. Yours is to make it one JSON value. The companion article How to Format and Validate JSON is the happy path. This page is the failure path.

Do not start in the viewer, the graph, or the minifier. Those assume a document.

Trailing commas, single quotes, and comments

These are the daily drivers.

Trailing comma. {"ok": true,} or ["a",]. Legal in modern JS. Illegal in JSON. Delete the comma.

Single quotes. {'sku': 'A-104'}. JSON strings use ". Replace quotes carefully if the values contain apostrophes ("item's").

Unquoted keys. {sku: "A-104"}. Quote the key.

Comments. // todo or /* */. Strip them. If you need comments long-term, the file wanted YAML, not JSON. Convert with YAML to JSON only if the whole file is YAML, not if you sprinkled comments into JSON.

undefined, NaN, Infinity. Not JSON. Use null or omit the key. JSON.stringify in a browser console drops undefined keys and turns NaN into null. Know which you want.

Trailing commas in pretty-printed diffs. Someone edited a fixture in an editor that added a comma after the last property. The file was valid last week. Git blame the comma.

Truncated responses and extra text

Cut-off paste. The array never closes. The formatter will fail near the end. Scroll to the last character. Restore from the network panel with a cleaner copy, or reconstruct only if you know the missing tail. Do not invent ] } blindly on a customer export.

Headers above the body.

HTTP/1.1 200 OK
Content-Type: application/json

{"ok":true}

Delete everything before { or [.

Log prefixes. 2026-08-23T12:00:00Z GET /v1/orders {"ok":true}. Keep the object. Drop the rest.

Concatenated documents. {"a":1}{"b":2} or }{. Split. Format twice.

NDJSON. One value per line. Split on newlines. A single formatter box is the wrong tool for a 10,000-line stream; sample a line.

Trailing junk. {"ok":true}<br> or a second copy-paste. Remove it.

BOM and smart quotes. A UTF-8 BOM or from a chat app will fail. Re-type the quotes.

Single-quoted JSON-ish from Python print. That is not JSON. Use json.dumps on the producer, or fix quotes by hand for a small object.

A network-panel copy that fails

You copy a POST response. The formatter says unexpected token at position 18420. You jump there and find ,"debug": cut off mid-key. The response was truncated by the copy, not by the server. Recopy from the response tab, or save the response as a file and paste the whole file.

Second case: the body is JSON wrapped in a callback: /**/callback({"ok":true}). That is JSONP. Strip the padding.

Third case: the “JSON” is XML. The first character is <. Use XML to JSON, not a JSON fixer.

Fourth case: the body is YAML from a mislabeled download. Use YAML to JSON.

If the payload includes Authorization or a user email, redact after it parses, before you share the pretty copy. Fixing syntax is not permission to spread secrets.

After it finally parses

Pretty-print and read it. If you need a path, JSON Viewer. If you need a compact fixture, redact, then JSON Minifier. If you needed this only to commit a file, do not keep the live response.

The minify guide is How to Minify JSON for Production. Minify is a last step, not a repair step.

Huge broken files: if the tab dies, the document is too big to repair in a browser. Split it. A 500 MB dump with one trailing comma is a jq or editor job on your machine.

What a formatter will not repair

It will not guess your schema. It will not merge two halves of different responses. It will not unescape a string that is double-encoded ("{\"ok\":true}" is valid JSON - a string - not an object; parse twice if you meant an object). It will not fix UTF-8 that is actually Latin-1 mojibake beyond what you can see.

“JSON repair” sites that silently delete the last property are worse than an error. Fail closed. Edit the text. Confirm with a second parse in your own console: JSON.parse(copy).

Fix the first error, format again, repeat

Paste the broken text into JSON Formatter. Fix the first error only, format again, repeat. When it parses, follow the format and validate guide if you still need the working view. When you are ready to ship a compact copy, use JSON Minifier. The hub is JSON tools.

Frequently asked questions

Does fixing JSON on DevOkk require an account?

No. Paste the text into JSON Formatter, read the error, edit, format again. No registration.

Does the formatter upload my broken payload?

JSON Formatter is designed to process the text in your browser. Still avoid pasting production tokens or PII into any website. Browser-local is the safer default.

Can the formatter auto-repair my file?

No. It fails closed and points at syntax. You change the text. That is better than a silent 'fix' that deletes a field.

Why does it fail when JavaScript accepts the same object?

Object literals allow trailing commas, single quotes, unquoted keys, and undefined. JSON does not. Use JSON.stringify in a console you control, or edit the text to the JSON grammar.

What about NDJSON or two objects stuck together?

That is not one JSON document. Split on newlines or on the }{ boundary. Format each value separately.

When do I minify?

After it parses and after you redact secrets. Minifying invalid text does not help. See the minify guide for the production step.

More reading that links back to the same tools and workflows.