Formatting and validating JSON, and finding the one bad character
Four mistakes cause almost every JSON parse error. Trailing commas top the list.
A JSON formatter does two jobs. It pretty-prints a minified blob so a human can read it, and it validates the syntax so you find out exactly where the structure is broken instead of staring at an API error.
Almost every JSON parse failure is one of four things: a trailing comma after the last item, single quotes instead of double, an unquoted key, or an unescaped character inside a string. JSON is stricter than JavaScript object literals, which is why code that looks fine to a developer fails to parse. The formatter is in the ToolHub developer section.
JSON Formatter: the facts that matter
| Functions | Format, validate, minify |
| Error reporting | Position of the parse failure |
| Top cause of failure | Trailing comma |
| Comments | Not valid in JSON, despite what editors allow |
| Privacy | Runs in the browser; nothing sent to a server |
How to do it, step by step
- 1Open the JSON formatter in ToolHub and paste your JSON.
- 2Format it. If it is invalid, you get an error position instead.
- 3Go to the reported position, then look at the character just before it. The real problem is usually one character earlier than the error points to.
- 4Check the four usual suspects: trailing comma, single quotes, unquoted key, unescaped character.
- 5Minify before sending JSON over the wire, and format when you need to read it.
Three things worth knowing
- Trailing comma first. Check it before anything else, it is the most common cause by a wide margin.
- Minify for transport, format for reading. Sending pretty-printed JSON wastes bandwidth on every request.
- A browser-based formatter keeps the data local, which matters when the JSON contains anything sensitive.
Common problems, solved
Where to run it
This tool is part of the ToolHub tool library, a library of over 1,000 browser-based tools covering PDF, image, video, audio, text and developer work. Everything runs in the browser and none of it needs an account.
ToolHub is built by codaiman.com, an AI-first software company in Ahmedabad. Related to this page: Web development custom websites and web apps in react, next.js and typescript, including pwas and api work.
JSON Formatter, in the browser: no install, no sign-up, no upload queue. Part of the ToolHub library from CodeAiMan.
Open ToolHubRelated tools
Base64 Encoder / Decoder
Base64 is encoding, not encryption. Anyone can decode it instantly, which matters more than most people realise.
Read guideURL Encoder / Decoder
Spaces, ampersands and question marks break URLs. Encoding fixes it, and double-encoding breaks it differently.
Read guideHash Generator
MD5 is fine for checking a download. It is completely unfit for passwords, and so is SHA-256 on its own.
Read guide