<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Pepsi</title>
    <description>The latest articles on DEV Community by Pepsi (@unicode-dev).</description>
    <link>https://dev.to/unicode-dev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3805178%2F940819a7-44a0-45b7-be33-8e15a27b6098.png</url>
      <title>DEV Community: Pepsi</title>
      <link>https://dev.to/unicode-dev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/unicode-dev"/>
    <language>en</language>
    <item>
      <title>Why JSON.parse Fails on Valid JSON (Hidden Unicode Characters)</title>
      <dc:creator>Pepsi</dc:creator>
      <pubDate>Wed, 04 Mar 2026 06:11:08 +0000</pubDate>
      <link>https://dev.to/unicode-dev/why-jsonparse-fails-on-valid-json-hidden-unicode-characters-dph</link>
      <guid>https://dev.to/unicode-dev/why-jsonparse-fails-on-valid-json-hidden-unicode-characters-dph</guid>
      <description>&lt;p&gt;Sometimes JSON.parse throws an “Unexpected token” error even when the JSON looks completely valid.&lt;/p&gt;

&lt;p&gt;This confused me for a long time.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;const json = '{ "name": "John" }';&lt;br&gt;
JSON.parse(json);&lt;/p&gt;

&lt;p&gt;Looks correct, right?&lt;/p&gt;

&lt;p&gt;But sometimes when copying JSON from Slack, Word, Notion, or ChatGPT, hidden Unicode characters are inserted into the string.&lt;/p&gt;

&lt;p&gt;Common culprits include:&lt;/p&gt;

&lt;p&gt;• Zero Width Space (U+200B)&lt;br&gt;&lt;br&gt;
• Byte Order Mark / BOM (U+FEFF)&lt;br&gt;&lt;br&gt;
• Non-breaking space (U+00A0)&lt;/p&gt;

&lt;p&gt;These characters are invisible, but they break parsers.&lt;/p&gt;

&lt;p&gt;Example with hidden character:&lt;/p&gt;

&lt;p&gt;{​ "name": "John" }&lt;/p&gt;

&lt;p&gt;That tiny invisible character before the quote can cause:&lt;/p&gt;

&lt;p&gt;Unexpected token in JSON at position X&lt;/p&gt;

&lt;p&gt;Debugging this is frustrating because the character cannot be seen in most editors.&lt;/p&gt;




&lt;h3&gt;
  
  
  Quick Fix in JavaScript
&lt;/h3&gt;

&lt;p&gt;You can remove common hidden characters with:&lt;/p&gt;

&lt;p&gt;str.replace(/[\u200B-\u200D\uFEFF]/g, "")&lt;/p&gt;

&lt;p&gt;But first you need to &lt;strong&gt;detect them&lt;/strong&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  Tool to Detect Hidden Unicode Characters
&lt;/h3&gt;

&lt;p&gt;While debugging this issue I built a small browser tool that helps detect and remove invisible Unicode characters.&lt;/p&gt;

&lt;p&gt;It highlights things like:&lt;/p&gt;

&lt;p&gt;• Zero Width Space&lt;br&gt;&lt;br&gt;
• BOM&lt;br&gt;&lt;br&gt;
• Non-breaking spaces&lt;br&gt;&lt;br&gt;
• Other hidden Unicode&lt;/p&gt;

&lt;p&gt;You can try it here:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://unicodecleaner.online" rel="noopener noreferrer"&gt;https://unicodecleaner.online&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The tool runs &lt;strong&gt;100% client-side&lt;/strong&gt;, so text never leaves your browser.&lt;/p&gt;




&lt;h3&gt;
  
  
  Why This Happens
&lt;/h3&gt;

&lt;p&gt;Many tools automatically insert formatting characters when copying text. These characters are valid Unicode but not expected by strict parsers.&lt;/p&gt;

&lt;p&gt;So the JSON looks correct but fails to parse.&lt;/p&gt;




&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;If JSON.parse fails on valid-looking JSON:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Check for hidden Unicode characters
&lt;/li&gt;
&lt;li&gt;Log character codes
&lt;/li&gt;
&lt;li&gt;Strip zero-width characters&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Invisible characters are a surprisingly common source of parsing bugs.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>opensource</category>
      <category>debugging</category>
    </item>
  </channel>
</rss>
