SyntaxError: Unterminated string in JSON at position N means the parser started reading a string (saw an opening ") and reached the end of the input — or a line break — before finding the closing ". The string was never closed. Here's why that happens and how to fix it.
Which string-error am I getting?
- Unterminated string — a string was opened with
"but never closed. - Bad control character — a raw tab/newline/null byte sits inside a string without escaping.
- Bad escaped character — a
\is followed by something JSON doesn't allow (e.g.\x, Windows paths).
What the Error Looks Like
// V8 (Chrome / Node / Edge)
SyntaxError: Unterminated string in JSON at position 27
// Firefox
SyntaxError: JSON.parse: unterminated string at line 2 column 10 of the JSON data
// Safari
SyntaxError: JSON Parse error: Unterminated stringThe position points at (or just after) the opening quote of the string that never closed — work forward from there.
Why It Happens
Cause 1 — An unescaped quote ends the string early
A literal " inside a value closes the string prematurely; the rest of the line is then read as unexpected tokens, and the real string is left "open."
// ❌ broken — the quote before hello closes "He said "
{ "note": "He said "hello" to her" }
// ✅ fixed — escape inner quotes with backslash
{ "note": "He said \"hello\" to her" }Cause 2 — A raw line break inside the string
JSON strings can't span raw newlines. A literal line break terminates the string and leaves it unclosed.
// ❌ broken — real newline inside the string
{ "bio": "line one
line two" }
// ✅ fixed — use the \n escape, no raw newline
{ "bio": "line one\nline two" }Cause 3 — Truncated data
A response cut off mid-string (dropped connection, buffer/size limit, partial read) leaves a string open at the end of the input.
// what arrived (connection dropped):
{"user":{"name":"Ada Lovel
// → Unterminated stringHow to Fix It — Step by Step
- Go to the reported position and find the opening
"that has no matching close. - Look for an unescaped
"inside the value — escape it as\". - Look for a raw newline/tab in the value — replace it with
\n/\t. - Check for truncation — compare the byte length to
Content-Length; if short, the data was cut off (a code fix, not a text fix). - Stop hand-building JSON. Use
JSON.stringify(), which escapes quotes and control characters for you.
// Prevention: never concatenate strings into JSON
const json = JSON.stringify({ note: userInput }); // always validFrequently Asked Questions
What causes "Unterminated string in JSON"?
An opening " with no matching closing " — usually an unescaped quote inside the value, a raw line break, or a response that was truncated mid-string.
How do I include a quote or newline inside a JSON string?
Escape them: \" for a double quote, \n for a newline, \t for a tab. Building the JSON with JSON.stringify() does this automatically.
Is this the same as "Unexpected end of JSON input"?
Related but distinct. "Unterminated string" means a string is open; "Unexpected end of JSON input" means the whole structure (object/array) ended early. Truncated responses can trigger either.
Fix It Now
- JSON Fix — find the unterminated string and repair it in your browser
- Unexpected End of JSON Input — when the whole structure is cut off
- Bad Control Character in String Literal in JSON — raw tabs/newlines in strings
- Bad Escaped Character in JSON — invalid backslash escapes