Reading and Debugging JSON: A Practical Guide

2026-06-03 · 5 min read

Trailing commas, single quotes, missing brackets — the usual suspects behind "Unexpected token". Here is how to fix them fast.

JSON (JavaScript Object Notation) is the lingua franca of APIs. Its rules are strict, which is good for machines but means a single stray character breaks the whole document. Knowing the common pitfalls makes debugging quick.

The core syntax rules

The errors you will actually hit

The infamous "Unexpected token" almost always means a trailing comma, a single quote, an unquoted key, or a missing bracket. The error usually reports a position — start reading just before it.

Prettify to see structure

Minified JSON on one line is unreadable. Formatting it with indentation reveals nesting and makes a missing or extra bracket obvious. Sorting keys alphabetically helps when comparing two payloads.

When an API response will not parse, paste it into a validator first. It is faster than scanning by eye and points you straight at the offending character.

Format and validate

The JSON Formatter prettifies, minifies, and validates JSON with inline error highlighting and a character position, so you can fix broken payloads in seconds.

Try the JSON Formatter →