An API returning invalid JSON almost always traces back to one of a small set of repeat offenders — and once you know the pattern, debugging goes from guesswork to a quick checklist.

The usual suspects

  • A trailing comma left after the last item in an array or object
  • Unescaped quotes inside a string value
  • The server accidentally returning an HTML error page instead of JSON, often with a valid HTTP 200 status
  • Mixed single and double quotes, when JSON strictly requires double quotes

A faster way to isolate the problem

Rather than scanning a large payload by eye, paste the raw response into a JSON formatter and validator. A good validator will point to the exact character or line where parsing failed, which turns a five-minute manual hunt into a five-second fix.

Prevent it upstream

If you control the API, validating your response body before it's sent — and setting the correct Content-Type: application/json header — prevents most of these issues from reaching consumers in the first place.

Ready to try it? Jump back up to the JSON Formatter & Validator.