Skip to content

How-to guide · 5 min read

JSON Errors Explained: How to Find and Fix Invalid JSON

The most common reasons JSON fails to parse — trailing commas, single quotes, comments — and how to fix them fast.

GGuru GUpdated November 8, 2026

JSON is stricter than JavaScript

JSON looks like a JavaScript object, but the format is deliberately strict so every language can parse it the same way. Many 'invalid JSON' errors come from writing JavaScript habits into a JSON file.

The usual suspects

If a formatter reports an error, check these first:

  • Trailing commas: {"a": 1,} is invalid. Remove the comma before } or ].
  • Single quotes: strings and keys must use double quotes.
  • Unquoted keys: {name: "x"} must be {"name": "x"}.
  • Comments: // and /* */ are not allowed in standard JSON.
  • Special values: undefined, NaN and Infinity aren't valid; use null or a string.
  • Unescaped characters: a raw newline or tab inside a string must be written as \n or \t.

Reading the error position

Parsers report the position where they gave up, which is often just after the real mistake. Our JSON Formatter converts that position into a line and column; look at the character it points to and the one just before it.

Formatting for humans vs machines

Pretty-printed JSON with 2-space indentation is easiest to review in code and pull requests. Minified JSON removes all whitespace, which saves bytes in APIs and config payloads. Sorting keys makes diffs cleaner when two systems produce the same data in different orders.

Privacy

Developers often paste API responses that contain personal or secret data. All Painkillers.io developer tools run locally in your browser, so the data you format never leaves your device.