Skip to main content
Developers JSON Debugging

A practical guide to JSON formatting

How to read, validate and fix JSON, what the most common syntax errors are, and how to convert JSON into other formats without writing code.

The Tools Today5 min read

JSON is the lingua franca of the modern web, and also the format most likely to end up broken somewhere in a log, a configuration file or a copy-pasted API response. The good news is that JSON errors are almost always one of a small number of predictable mistakes, and most of them can be found in seconds.

The five errors you will actually hit

  • A trailing comma after the last item in an object or array. This is the most common mistake by a wide margin.
  • Unescaped quotes inside a string value, for example a "quote" in a sentence that is itself wrapped in double quotes.
  • Single quotes instead of double quotes. JSON requires double quotes around keys and string values.
  • Comments. JSON has no comment syntax, so // and /* */ make a document invalid.
  • A missing or doubled comma between two values, or a comma where a colon belongs.

Why a formatter helps more than a validator

A validator tells you that something is wrong; it rarely tells you where. A formatter is more useful because pretty-printing with indentation exposes the structure, and the structure makes the mistake obvious. A missing comma between two long blocks, for instance, is invisible in a single-line blob and obvious once the document is indented. This is why reaching for a formatter before staring at a wall of minified JSON is the right instinct.

Going further

Once the JSON is valid, it becomes far easier to work with. Converting it to TypeScript interfaces gives you a typed representation of a payload without writing the definitions by hand. Converting it to CSV turns an array of objects into a spreadsheet. Converting a JSON string into YAML makes configuration files readable and diff-friendly. All of those conversions are exact and lossless, and all of them can be done in the browser without sending your payload anywhere.

One final tip: when a JSON error appears at a specific line and column, that position is where the parser gave up, not necessarily where the mistake is. The real problem is often a few characters earlier — an unclosed string, for example, makes everything after it look wrong. Scanning backwards from the reported position is usually faster than scanning forwards.

Tools mentioned in this guide

← Back to all guides

Your privacy, your choice

We use cookies to understand how the site is used and to show relevant ads. Every tool on this site runs entirely in your browser, so the files and text you process are never uploaded. Read our privacy policy.