JSON Errors / JavaScript / Python

Unterminated string in JSON

How to Fix: Unterminated string in JSON

The parser found the opening double quote of a string but hit the end of a line - or the end of the input - before the closing quote. JSON strings must close on the same line: raw (unescaped) line breaks inside strings are illegal.

Python reports the same problems as "Unterminated string starting at: line X column Y" or "Invalid control character" - the control character being the raw newline.

{"find": "error"}paste your JSON below

Common causes

1. Raw line break inside a string value

Multi-line text pasted directly into a JSON string. JSON requires the newline to be escaped as \n.

Invalid
{"note": "line one
line two"}
Valid
{"note": "line one\nline two"}

2. Unescaped double quote inside a string

A quote inside the value terminates the string early; whatever follows becomes garbage and the real closing quote starts a new, never-closed string.

Invalid
{"quote": "She said "hi" to me"}
Valid
{"quote": "She said \"hi\" to me"}

3. Truncated document

The input got cut off mid-string (log line limits, dropped connections) - the closing quote simply never arrived.

How to fix it

Escape user text properly (never concatenate)
// Wrong: manual concatenation breaks on quotes/newlines
const bad = '{"note": "' + userText + '"}';

// Right: the serializer escapes everything
const good = JSON.stringify({ note: userText });
Accept literal newlines when parsing (Python, last resort)
import json

# strict=False allows raw control characters inside strings
data = json.loads(broken_text, strict=False)
# Better: fix the producer to escape \n properly

Frequently asked questions

Why are raw newlines forbidden inside JSON strings?

Control characters (below U+0020) must be escaped so that JSON stays unambiguous to parse and safe to embed in other formats and logs. A newline in the data is written as the two characters \n, and the parser turns it back into a real newline.

How do I store multi-line text in JSON then?

Exactly as one string with \n escapes - serializers do this automatically. If humans need to edit the multi-line text comfortably, consider YAML (which supports block strings) or store the text in a separate file.

The error points at a line that looks fine. Where is the real problem?

The unterminated string usually starts earlier than where the parser gives up - an unescaped quote a few lines up shifts everything. Paste the JSON into the validator on this page; it highlights the exact character where parsing derailed.

Last updated:

Related JSON errors

You might also need

Free and in-browser, like everything on JSON Console. Browse all tools →