🔧 JSON Formatter & Validator: Debug JSON Like a Senior Developer (2026)

📅 2026-05-26 ⏱️ 4 min read 🏷️ Development

You're staring at a single-line, 2000-character JSON response from an API. Somewhere in there is the data you need, but finding it means scrolling sideways through a wall of escaped quotes. Or worse — your JSON.parse() failed and the error message just says "Unexpected token at position 847." Here's a systematic debugging workflow that saves hours.

The JSON Debugging Workflow (30 Seconds)

  1. Copy the raw JSON — API response, config file, localStorage dump, whatever.
  2. Paste into a formatter. A good JSON formatter auto-formats AND validates in real-time.
  3. Read the error highlight. A good tool highlights the exact line and character: "Unexpected comma at line 47, column 23."
  4. Fix the error (see the 5 most common below).
  5. Re-validate. When it formats cleanly, copy the formatted JSON and move on.

Use a JSON formatter that does both — formatting and validation — in one paste. Client-side formatters (processing in the browser) are preferred for debugging sensitive API responses (auth tokens, user data, payment payloads).

The 5 Most Common JSON Errors (And Exactly How to Fix Them)

1. Trailing Comma

The most common JSON syntax error. JavaScript objects and arrays allow trailing commas — JSON does not. If your error says "Unexpected token }" in an object, or "Unexpected token ]" in an array, look one line above. There's a comma where it doesn't belong. This happens constantly when developers hand-write JSON or generate JSON using string concatenation instead of a serializer.

2. Unquoted or Single-Quoted Keys

JSON strictly requires double quotes around all keys and string values. {name: "John"} is valid JavaScript but invalid JSON. {'name': 'John'} uses single quotes — also invalid. Python developers are especially prone to this because Python's dict syntax uses single quotes. Always use double quotes in JSON. If you're generating JSON from code, use JSON.stringify() or your language's JSON module — never hand-build JSON strings.

3. Comments in JSON

JSON does not support comments — no // line comments, no /* block comments */. This is by design: Douglas Crockford, JSON's creator, explicitly excluded comments to prevent parsing directives from being embedded in data interchange. If you need comments in a config file, use JSONC (VS Code's JSON with Comments format), JSON5 (a superset that allows comments and trailing commas), or YAML. If you must embed comments in a JSON data file, add a "_comment" field — but your parser needs to handle it.

4. Boolean and Number Formatting

Booleans in JSON are lowercase: true and false — not True, False, TRUE, or "true" (quoted strings are not booleans). Numbers don't have quotes: "count": 42 not "count": "42". JSON doesn't support NaN, Infinity, or undefined — use null for missing values. These type mismatches cause silent bugs rather than parse errors — your API consumes a string "42" but expects a number and your validation passes because JavaScript's loose equality doesn't care until you try to do math.

5. Deep Nesting and Data Overload

The error isn't syntax — it's usability. A 50-level-deep API response is impossible to read as flat text. Use a formatter with tree view/collapse. Learn the jq command-line tool:

# Pretty-print and filter: show only .data.users[].name
curl -s api.example.com/users | jq '.data.users[].name'

# Format a local file
jq . messy.json > clean.json

# Extract a specific path from a huge response
jq '.items[] | {id, title: .metadata.title}' response.json

Format vs Minify: When to Use Which

  • Format (pretty-print): Development, debugging, code review, documentation. Formatted JSON is human-readable.
  • Minify (compact): Production API responses, data stored in localStorage or IndexedDB, embedding in HTML data attributes. Minified JSON is typically 20-30% smaller due to whitespace removal. Combined with gzip compression, the difference is smaller (~5-10%) but still worthwhile for high-traffic APIs.

Use the Minifier to compress JSON for production and the JSON Formatter to expand it for debugging.

Pro Tips

  • Bookmark a formatter. You'll use it multiple times per day if you work with APIs. The 2 seconds saved over Googling "json formatter" every time adds up.
  • Watch for BOM characters. If validation fails on a perfectly valid-looking JSON file, check for invisible Byte Order Mark (U+FEFF) at the start. Some Windows editors (Notepad, older Visual Studio) add BOM by default. Strip it with sed '1s/^\xEF\xBB\xBF//'.
  • Validate before POSTing. Format and validate your request body before sending it — saves debugging "400 Bad Request" with unhelpful error messages.
  • Use JSON Schema for API contracts. Validate that the structure matches expectations, not just syntax. Tools like AJV (JavaScript) validate JSON against a schema definition.

Found this helpful? Explore 100+ free online tools — no signup needed.