formatjson.pro
Validate, pretty-print or minify JSON in your browser — nothing is uploaded.

Unexpected non-whitespace character after JSON data

JSON.parse() finished a complete value and then found more non-space characters. It is the JavaScript twin of Python's "Extra data": you most likely have two JSON values concatenated or JSON Lines being parsed as one string. Split the input and parse each value separately.

What the error means

Newer V8 (Node 20+, modern Chrome) reports trailing content with this message instead of the old generic "Unexpected token". The JSON up to that point was valid; there is simply extra data after it.

The common causes

1. JSON Lines / NDJSON. Split on newlines and parse each line: text.trim().split('\n').map(l => JSON.parse(l)).
2. Concatenated responses. Two payloads joined into one string. Separate them before parsing, or decode incrementally.
3. Duplicated or appended output. A logging step or a retried write doubled the body. Keep only the first complete value.

Fix it fast

This is a structural problem, not a typo, so the repair tool above only validates a single value at a time — paste one object to confirm it parses, then handle the multiple values in code by splitting the input.

FAQ

Why did I only start seeing this error recently?

V8 changed the wording. Older Node/Chrome said "Unexpected token" for the same trailing-data problem; Node 20+ says "Unexpected non-whitespace character after JSON data".

How do I parse NDJSON in JavaScript?

Split on newlines and map JSON.parse over the non-empty lines: text.trim().split('\n').filter(Boolean).map(l => JSON.parse(l)).

Is a trailing newline a problem?

No — whitespace after the value is allowed. Only non-whitespace characters after the first complete value trigger this error.