Unexpected non-whitespace character after JSON at position N

ErrorJavaScript

SyntaxError: Unexpected non-whitespace character after JSON at position 26 (line 2 column 1)

Where it stops

{"id": 1, "status": "ok"}
{"id": 2, "status": "ok"}

What it means

JSON.parse reads exactly one value. It read one, the value was fine, and then it found more text. Your first value is not broken. Something follows it, and the position tells you exactly where that something starts.

Last verified on Chromium 145, Firefox 146, WebKit 26 and Node 20.

The validator opens with the error marked. Examples travel in the URL fragment, which browsers never send to a server.

Express Lint formats broken JSON so you can find the error, and marks the line where it stops. It changes only spaces and line breaks outside strings. Strings in either quote stay as written. If the quotes do not pair up, it leaves your text as it is. Ctrl+Z undoes it. See how it works.

Usually
Two JSON documents in one stringIt is JSON Lines, not JSONA stray character at the endA brace that closed the document early
Fix
Work out which format you have.

The fix

Work out which format you have. If it is JSON Lines, parse one line at a time with text.split("\n").filter((line) => line.trim()).map((line) => JSON.parse(line)). If it should be one document, wrap the values in [ ] with commas between them, as the fixed example does. If it is one stray character, delete it.

broken.jsonFails to parse
{"id": 1, "status": "ok"}
{"id": 2, "status": "ok"}
JSON.parse stops at line 2, column 1.

Lines 1, 2, 3 and 4 change.

fixed.jsonParses
[
  {"id": 1, "status": "ok"},
  {"id": 2, "status": "ok"}
]
JSON.parse reads it.

How the message appears

Chrome and Node first, then Firefox, then Safari. Current V8 adds the line and column after the position, and Node 20 does not. Safari does not say what it found, only that it failed.

Console
  • SyntaxError: Unexpected non-whitespace character after JSON at position 26 (line 2 column 1)Chrome and Node
  • SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data at line 2 column 1 of the JSON dataFirefox
  • SyntaxError: JSON Parse error: Unable to parse JSON stringSafari
  • SyntaxError: Unexpected non-whitespace character after JSON at position 26Older V8 wording
  • SyntaxError: Unexpected token { in JSON at position 26Older V8 wording

What causes it

  1. Two JSON documents in one string

    Two responses written into one buffer, a file that was appended to, or two JSON.stringify results joined together. The position lands on the second {, and each half parses on its own.

  2. It is JSON Lines, not JSON

    One object per line, no commas and no surrounding array. Logs, exports and streaming APIs use this format on purpose, often in .jsonl or .ndjson files. Nothing is wrong with the text. It needs a different reader.

  3. A stray character at the end

    A trailing comma or semicolon, one closing brace too many, or text that a template added after the JSON. {"a": 1}; fails at position 8, which is the semicolon.

  4. A brace that closed the document early

    An extra } in the middle ends the top-level object before you meant it to, and everything after it counts as extra. In {"a": {"b": 1}}, "c": 2} the position points at the comma, but the mistake is the brace just before it.

Worth knowing

Watch outCheck what reads the file before you turn JSON Lines into an array. The format exists so a large file can be processed one line at a time, and an array has to be held in memory whole.

NotePython reports the same thing as Extra data: line 1 column N (char N), and that page covers the Python side.

What you put into the tools never leaves your browser. We count page views and keep them for 90 days. Accept and we also remember this browser, so a return visit is not counted as new. Privacy policy