Unterminated string in JSON at position 75
Updated by John Marshall
This SyntaxError comes from JSON.parse reaching the end of the text while it is still inside a string. Either the JSON was cut off partway through a value, or the text is complete and a closing quote is missing.
The position is the length of the text. It marks where the text stops, and the string that never closed starts somewhere before it.
Quick fix
- Look at the last characters of the text.
- If it stops in the middle of a value, with no closing
}or], it was cut off. Fetch or export it again. - If it ends with
}or], a string is missing its closing quote. Paste the JSON below to see which string gets closed.
Fix your JSON
JSON that was cut off
Where the text stops decides the message. These are from Node.js 20:
| The text ends with | Message |
|---|---|
{"robot": "TIDY-002", "status": "stu | Unterminated string in JSON at position 36 |
{"robot": "TIDY-002", "status": "stuck" | Expected ',' or '}' after property value in JSON at position 39 |
{"robot": "TIDY-002", "status": "stuck", | Expected double-quoted property name in JSON at position 40 |
{"robot": "TIDY-002", "status": | Unexpected end of JSON input |
Unexpected end of JSON input covers the usual reasons: a response that ends early, a stream parsed before it finishes, a model reply that reaches its token limit, and a file that is still being written.
Storage with a fixed size cuts every long value at the same length, so log the length when the parse fails:
try {
JSON.parse(text);
} catch (error) {
console.log(error.message);
console.log(text.length, text.slice(-20));
}Unterminated string in JSON at position 75
75 under": "standing deA length of 65,535, or another limit such as 255 or 4,096, points to a column, log field or buffer of that size. A MySQL TEXT column holds 65,535 bytes. With strict SQL mode off, MySQL shortens a longer value to fit and raises a warning, so the insert succeeds and the end of the JSON is gone. MEDIUMTEXT holds about 16 MB, and MySQL’s JSON type rejects a document that isn’t valid.
A missing closing quote
{"robot": "TIDY-002", "stuck_under": "standing desk}The last string in this text has no closing quote. Python’s message says where that string starts: Unterminated string starting at: line 1 column 38 (char 37).
A quote missing earlier in the text is usually reported differently, because the next quote closes the string and the parser fails on what follows. On one line, {"robot": "TIDY-002, "stuck_under": "standing desk"} gives Expected ',' or '}' after property value. Across several lines, the string reaches the line break first, and Chrome and Firefox report Bad control character in string literal. Safari calls that case Unterminated string as well.
A backslash before the closing quote
{"log_dir": "C:\\crumbpatrol\\logs\"}\" is the escape for a double quote, so the parser reads the last quote as part of the value and the string runs to the end of the text. The other backslashes in this path are doubled and the final one isn’t. Written as "C:\\crumbpatrol\\logs\\", it parses. A single backslash before a letter such as U is reported as Bad escaped character.
The same error elsewhere
| Chrome, Edge | Unterminated string in JSON at position 75 (line 4 column 30) |
|---|---|
| Node.js 20 | Unterminated string in JSON at position 75 |
| Firefox | JSON.parse: unterminated string at line 4 column 30 of the JSON data |
| Safari | JSON Parse error: Unterminated string |
| Python | json.decoder.JSONDecodeError: Unterminated string starting at: line 4 column 18 (char 63) |
| Go, json.Unmarshal | unexpected end of JSON input |
| Swift, JSONSerialization | Unterminated string around line 4, column 17. |
| jq | jq: parse error: Unfinished string at EOF at line 4, column 29 |