Code Tools StudioCode Tools Studio
All Tools
Tools
JSON FormatterCode MinifierRegex TesterPDF MergePDF SplitPDF to TextImage ConverterJSON Schema GeneratorText Case ConverterBase64 Encoder/DecoderURL Encoder/DecoderHash GeneratorUUID GeneratorColor ConverterTimestamp ConverterLorem Ipsum GeneratorJWT DecoderText Diff CheckerMarkdown Previewer

Command Palette

Search tools and actions

Guides

How to Fix Invalid JSON: Every Common JSON.parse() Error, Explained

Code Tools Studio·5 min read·March 10, 2026

JSON.parse() fails loudly but not always clearly. The error message tells you where it broke, not why in plain English. Here's a translation for the ones you'll actually hit, and the fastest way to find the exact spot: paste the payload into the JSON Formatter, which reports the precise line and column instead of just a character offset.

"Unexpected token ) in JSON at position X"

Almost always a trailing comma: {"a": 1, "b": 2,}. Valid in a JavaScript object literal, invalid in JSON. Remove the comma before the closing brace or bracket.

"Unexpected token ' in JSON at position X"

JSON requires double quotes, not single quotes, around strings and keys. {'a': 1} needs to become {"a": 1}. This one usually shows up when JSON gets hand-copied out of JavaScript source code, where single quotes are valid.

"Unexpected token a in JSON at position X" (or any bare letter)

Usually an unquoted key: {a: 1} is JavaScript object shorthand, not JSON — keys need quotes too: {"a": 1}.

"Unexpected end of JSON input"

The input is truncated: a string that got cut off mid-response, an empty string being parsed, or a closing brace/bracket that's missing entirely. Check the very end of the payload; a network response cut short by a timeout is a common real-world cause.

"Unexpected token u in JSON at position 0"

This is JSON.parse(undefined) in disguise: undefined gets coerced to the string "undefined", and JSON parsing chokes on the letter u. Check whatever produced the input; you're parsing a value that was never actually set.

Unescaped control characters inside a string

A literal newline or tab character inside a JSON string value breaks parsing; it needs to be the escape sequence \n or \t instead. This tends to happen when JSON is built by hand-concatenating strings rather than using a proper serializer.

The fastest way to actually find it

  1. Paste the full payload into the JSON Formatter.
  2. Read the reported line and column, not just the error type.
  3. Fix that one spot; malformed JSON usually has exactly one break point, and everything after it just looks broken as a side effect.

If the payload is valid JSON but you're not sure it should look the way it does, generating a JSON Schema from a known-good example gives you something to validate future payloads against, instead of eyeballing it each time.

Code Tools Studio - 19 privacy-first tools for everyday developer tasks | Product Hunt
Files auto-deleted after 1 hour TLS 1.3 encrypted 99.9% uptime
PrivacyTermsBlog

© 2026 Code Tools Studio. All rights reserved.