If you have ever copied a perfectly formatted JSON payload from ChatGPT only to encounter SyntaxError: Unexpected token, the problem is rarely your logic. The issue is almost always invisible Unicode characters injected during copy-paste.
JSON is strict. According to the specification, only four whitespace characters are allowed outside strings:
Anything else — even if it looks like a space — will cause JSON.parse() to fail immediately.
An invisible formatting character inserted by browsers to manage line wrapping. It has no visual width but is illegal in JSON.
Looks identical to a normal space but is treated as a different Unicode character. JSON does not allow it.
Used in some encoding contexts but invalid inside JSON strings or structural content.
{
"server_config": {
"host": "127.0.0.1",
"port": 8080
}
}
function sanitizeJSONString(str) {
return str
.replace(/[\u200B-\u200D\uFEFF]/g, '')
.replace(/\u00A0/g, ' ');
}
const clean = sanitizeJSONString(raw);
const parsed = JSON.parse(clean);
All tools run 100% client-side. No uploads. No data storage.
AI-generated JSON is powerful but often contaminated with invisible formatting characters. Understanding U+200B, U+00A0, and U+FEFF prevents hours of debugging and ensures reliable parsing.
Sometimes the issue is caused specifically by a non-breaking space — see the difference between NBSP and regular space.