FormatWell

Guides / JSON errors

Unexpected non-whitespace character after JSON

How it appears per engine

  • Uncaught SyntaxError: Unexpected non-whitespace character after JSON at position 17 (Chrome / Node.js)
  • SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data at line 2 column 1 of the JSON data (Firefox)

What this error means

The parser successfully read one complete JSON value — and then found more content after it. A JSON document must be exactly one value; anything after it (except whitespace) is an error.

This error is special: your data may not be broken at all. It may simply be JSON Lines (JSONL/NDJSON) — a format where every line is its own JSON value.

Common causes

1. The file is JSONL, not JSON

Log exports, LLM training data, and streaming APIs commonly emit one JSON object per line. JSON.parse reads the first line, then chokes on the second. Parse it line by line instead — or use a JSONL validator.

Fails

{"event":"start"}
{"event":"end"}  ← valid JSONL, invalid JSON

Works

const records = text
  .split("\n")
  .filter(Boolean)
  .map((line) => JSON.parse(line));

2. Two responses or objects concatenated

Appending API responses into one buffer or file without separators produces {"a":1}{"a":2}. Either store them as an array, or write one per line (JSONL).

3. Trailing garbage after the document

A stray character, a duplicated closing brace from a bad merge, or logging noise appended after the JSON. The position in the error tells you exactly where the extra content starts.

How to fix it

  1. If every line looks like its own JSON object — it is JSONL; validate it as JSONL and parse per line.
  2. Check the reported position: everything before it is valid, so inspect what follows.
  3. When accumulating multiple values, wrap them in an array or emit newline-delimited records.

Related errors