is not valid JSON
Unexpected token 'x', "xyz" is not valid JSON (the template: Unexpected token '<char>', "<input-preview>" is not valid JSON — introduced in Node 20 / Chrome 108)
The "is not valid JSON" suffix is the modern V8 error template introduced in Node 20 and Chrome 108. It combines the unexpected character, a preview of the input, and the "is not valid JSON" phrase into one message. If you search for this phrase, you likely saw it in a recent browser or Node 20+ environment. The error means the input string is not syntactically valid JSON — the specific character reported tells you what the parser tripped on. Common triggers include unquoted identifiers, JavaScript literals like undefined or NaN, and completely wrong content types.
JavaScript-specific values that are not valid JSON
undefined, NaN, Infinity, and -Infinity are valid JavaScript values but do not exist in JSON. JSON.parse rejects them. JSON.stringify converts undefined values to nothing (they are omitted from objects) and converts NaN/Infinity to null.
Invalid
JSON.parse("undefined") // throws
JSON.parse("NaN") // throws
JSON.parse("Infinity") // throwsValid
JSON.parse("null") // null is valid JSON
JSON.parse("42") // numbers are valid
JSON.parse('"text"') // strings are validUnquoted identifier used as a value
Bare words like true, false, and null are the only valid JSON literals without quotes. Any other unquoted word — a variable name, a type name, an enum value — is rejected.
Invalid
JSON.parse("hello") // unquoted string
JSON.parse("Date") // class name
JSON.parse("error") // bare wordValid
JSON.parse('"hello"') // quoted string
JSON.parse('null') // valid literal
JSON.parse('true') // valid literalJSON with JavaScript comments
JavaScript comments (// and /* */) are not valid JSON. They appear in JSONC files (tsconfig.json, .vscode/settings.json) but must be stripped before passing to JSON.parse.
Invalid
JSON.parse('{"timeout": 5000 /* ms */}')Valid
// Use a JSONC parser or strip comments first
import { parse } from "jsonc-parser"
const config = parse('{"timeout": 5000 /* ms */}')Empty or whitespace-only input
A completely empty string or a string with only whitespace is not valid JSON. Check that your input pipeline produces a non-empty string before parsing.
Invalid
JSON.parse(" ") // whitespace only
JSON.parse("") // empty stringValid
const raw = input?.trim()
if (raw) {
JSON.parse(raw)
}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
The error shows only part of my input — how do I see the full string?
V8 truncates the input preview in the error message for readability. To see the full string, log it before parsing: console.log('Input:', JSON.stringify(input)); (using JSON.stringify to safely display any special characters). This is especially useful when the input is binary-coerced or contains invisible characters.
My Node 18 app doesn't show "is not valid JSON" — is it a different error?
Yes. The "is not valid JSON" message template was introduced in V8 11.0 (Node 20, Chrome 108). Older engines use shorter messages like "Unexpected token x" without the input preview. Both indicate a JSON syntax error; the fix is the same regardless of the exact wording.