Unexpected non-whitespace character after JSON

Unexpected non-whitespace character after JSON at position 7 (line 1 column 8)

This error means the JSON parser successfully parsed a complete, valid JSON value, then found additional non-whitespace characters in the input. JSON.parse() expects exactly one top-level value followed by optional whitespace — nothing more. The extra characters are typically a second JSON document concatenated to the first, a trailing semicolon or comma left over from JavaScript source, or garbage bytes appended by a logging framework.

Two JSON documents concatenated (JSON Lines format)

Newline-delimited JSON (NDJSON / JSON Lines) stores one JSON object per line. If you read multiple lines and pass them all to a single JSON.parse() call, only the first object is valid and the rest produce this error. Split on newlines and parse each line individually.

Invalid

// Two objects in one string
JSON.parse('{"a":1}{"b":2}')

Valid

// Parse each line separately
const lines = text.split("\n").filter(Boolean)
const objects = lines.map(line => JSON.parse(line))

Trailing semicolon from JavaScript output

Some code generators or eval()-based serializers append a semicolon after the JSON value. JSON.parse sees the semicolon as an unexpected character.

Invalid

JSON.parse('{"key":"value"};')

Valid

JSON.parse('{"key":"value"}')

Trailing comma after the root value

A comma appended after the last top-level value — often from a concatenation bug — breaks parsing.

Invalid

JSON.parse('[1,2,3],')

Valid

JSON.parse('[1,2,3]')

Byte order mark (BOM) at the start or appended bytes

Some text editors save UTF-8 files with a byte order mark (U+FEFF) prepended or appended. The BOM is invisible in most editors but is treated as a non-whitespace character by JSON.parse.

Invalid

// File saved with BOM: {"key":"value"}
JSON.parse(fileContent)  // BOM causes error if at wrong position

Valid

const clean = fileContent.replace(/^\uFEFF/, "")
JSON.parse(clean)

Fix this error in seconds

Paste your JSON in the free validator to find the exact line and column where the error occurs.

Open JSON Validator →

Frequently Asked Questions

How do I handle a JSON Lines (NDJSON) file?

Split the string by newline, filter out empty lines, and call JSON.parse on each line: text.split('\n').filter(l => l.trim()).map(l => JSON.parse(l)). Libraries like ndjson or split2 handle this in Node.js streams with proper error handling per line.

What if the extra characters are not visible in my editor?

Invisible characters like the BOM (U+FEFF), null bytes, or zero-width spaces can cause this error. Run: [...text].map(c => c.codePointAt(0).toString(16)) in the browser console to inspect every character as a hex code point. Any value that does not belong to your JSON structure is the culprit.

More JSON errors