Why Your JSON Fails to Parse: Zero-Width Spaces Copied from ChatGPT
You ask ChatGPT for a config snippet. You copy it, paste it into your editor, and compare it with the file that works. The two look identical, character for character. Then you run it. In Node, a pasted file that starts with a byte order mark gives you this (the invisible character is written here as <U+FEFF> ; your terminal prints nothing at that position): SyntaxError: Unexpected token…
JSON parsing failures in Node and Python often stem from zero-width spaces copied from AI chat interfaces. These invisible characters -- U+200B, U+200C, U+200D, U+2060, U+FEFF, and U+00A0 -- do not affect the content of the answer but can cause parsing errors when pasted into source code. In Node, a BOM or U+200B at the beginning of a file results in a SyntaxError, while Python raises a SyntaxError for non-printable characters like U+200B.
Zero-width spaces are not tied to the content and can appear in JSON strings, causing issues with config[ name ] returning undefined due to the actual key being name\u200B. They can be identified using shell commands or in programming languages like Python and Node by mapping code points to their hexadecimal representations and filtering out unwanted characters.
When cleaning up the text, it's essential to preserve ZWJ between emoji to maintain the integrity of family emojis.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.