{"id":131,"date":"2026-05-26T19:13:08","date_gmt":"2026-05-26T19:13:08","guid":{"rendered":"https:\/\/json-beautifier.org\/blog\/?p=131"},"modified":"2026-05-26T19:13:09","modified_gmt":"2026-05-26T19:13:09","slug":"fix-invalid-json-common-errors","status":"publish","type":"post","link":"https:\/\/json-beautifier.org\/blog\/fix-invalid-json-common-errors\/","title":{"rendered":"How to Fix Invalid JSON: 10 Common Errors Every Developer Hits (With Real Examples)"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">You&#8217;ve spent twenty minutes staring at a JSON file. Your API call keeps failing. The error message is some cryptic nonsense about &#8220;unexpected token.&#8221; And the JSON <em>looks<\/em> fine to you.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We&#8217;ve all been there.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">JSON is a strict format. That strictness is what makes it reliable across every programming language on Earth &#8211; but it&#8217;s also what turns a missing comma into a debugging nightmare. The good news? Almost every broken JSON file fails for one of the same ten reasons. Once you know what to look for, you can spot the problem in seconds.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This guide covers all ten, with real examples of broken JSON and exactly how to fix each one. Bookmark it &#8211; you&#8217;ll come back.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Quick tip before we start:<\/strong> the fastest way to find any JSON error is to paste it into a<a href=\"https:\/\/json-beautifier.org\/\"> JSON validator<\/a>. A good one highlights the exact line and character where things go wrong, which saves a ton of squinting. But understanding <em>why<\/em> each error happens means you&#8217;ll write better JSON from now on &#8211; so let&#8217;s go through them.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. Trailing Commas<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This is the #1 mistake we see, and it&#8217;s almost always the culprit when JavaScript developers move from objects to JSON.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Broken:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"name\": \"Alice\",\n  \"age\": 30,\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That comma after 30 is illegal in JSON. JavaScript allows it. Python dicts allow it. JSON does not.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Fix:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>json\n{\n  \"name\": \"Alice\",\n  \"age\": 30\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Why this trips people up:<\/strong> Modern languages forgive trailing commas because they make diffs cleaner. JSON predates that convention, and the spec hasn&#8217;t budged.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Pro tip:<\/strong> When you reorder properties in an object, the new last property gets a comma it shouldn&#8217;t have. Always check the bottom of your object after any edit.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. Single Quotes Instead of Double Quotes<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Broken:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  'name': 'Alice'\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Fix:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>json\n{\n  \"name\": \"Alice\"\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">JSON only accepts double quotes \u2014 for both keys and values. No exceptions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Why this trips people up:<\/strong> Python&#8217;s default repr uses single quotes. Copy a dict from a Python console, paste it into a JSON file, and every quote is wrong. Same story with JavaScript object literals.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Pro tip:<\/strong> If you&#8217;re exporting JSON from Python, always use json.dumps(), never str(). Don&#8217;t hand-convert.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. Unquoted Keys<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Broken:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>json\n{\n\u00a0\u00a0name: \"Alice\"\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Fix:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>json\n{\n\u00a0\u00a0\"name\": \"Alice\"\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">JSON requires every key to be a string wrapped in double quotes. JavaScript lets you skip the quotes on simple keys. JSON does not.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is usually a dead giveaway that someone copy-pasted a JavaScript object and called it JSON. They&#8217;re related but they&#8217;re not the same thing.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4. Missing Commas Between Properties<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Broken:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>json\n{\n\u00a0\u00a0\"name\": \"Alice\"\n\u00a0\u00a0\"age\": 30\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Fix:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>json\n{\n\u00a0\u00a0\"name\": \"Alice\",\n\u00a0\u00a0\"age\": 30\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Every property pair (except the last) needs a comma after it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Why this one&#8217;s painful:<\/strong> the error message usually points to the <em>next<\/em> line, not the line missing the comma. So you&#8217;ll see &#8220;unexpected token at line 4&#8221; when the actual problem is on line 3. Always check the line above the one the error points to.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">5. Comments<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Broken:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>json\n{\n\u00a0\u00a0\/\/ This is the user object\n\u00a0\u00a0\"name\": \"Alice\"\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Fix:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>json\n{\n\u00a0\u00a0\"name\": \"Alice\"\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">JSON has no concept of comments. Not \/\/, not \/* *\/, not #. Nothing.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Workaround:<\/strong> If you really need to document a JSON config, add a comment key:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>json\n{\n\u00a0\u00a0\"_comment\": \"This is the user object\",\n\u00a0\u00a0\"name\": \"Alice\"\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Or use JSONC (JSON with Comments) \u2014 but only if you control the parser and you know it supports it. Most don&#8217;t.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">6. Unescaped Special Characters<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Broken:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>json\n{\n\u00a0\u00a0\"path\": \"C:\\Users\\Alice\"\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The backslashes aren&#8217;t escaped, so the parser tries to interpret \\U and \\A as escape sequences. Same problem if you have a literal double quote inside a string value:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>json\n{\n\u00a0\u00a0\"quote\": \"She said \"hi\"\"\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Fix:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>json\n{\n\u00a0\u00a0\"path\": \"C:\\\\Users\\\\Alice\",\n\u00a0\u00a0\"quote\": \"She said \\\"hi\\\"\"\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The escape sequences you&#8217;ll use most often in JSON: \\\\ (backslash), \\&#8221; (double quote), \\n (newline), \\t (tab), and \\uXXXX (unicode).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">7. Mismatched or Missing Brackets<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Broken:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>json\n{\n\u00a0\u00a0\"users\": &#91;\n\u00a0\u00a0\u00a0\u00a0{\"name\": \"Alice\"},\n\u00a0\u00a0\u00a0\u00a0{\"name\": \"Bob\"\n\u00a0\u00a0]\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Bob&#8217;s object is missing its closing brace. Easy to miss in a big file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Fix:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>json\n{\n\u00a0\u00a0\"users\": &#91;\n\u00a0\u00a0\u00a0\u00a0{\"name\": \"Alice\"},\n\u00a0\u00a0\u00a0\u00a0{\"name\": \"Bob\"}\n\u00a0\u00a0]\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This is where a<a href=\"https:\/\/json-beautifier.org\/\"> JSON beautifier<\/a> earns its keep. Properly indented JSON makes mismatched brackets visible immediately &#8211; what you can&#8217;t see in minified one-liner JSON jumps out the moment it&#8217;s formatted.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">8. Wrong Capitalization of <strong>true, false, and null<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Broken:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>json\n{\n\u00a0\u00a0\"active\": True,\n\u00a0\u00a0\"deleted\": Null\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Fix:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>json\n{\n\u00a0\u00a0\"active\": true,\n\u00a0\u00a0\"deleted\": null\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">JSON is case-sensitive. true, false, and null are all lowercase. Always.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Why this trips people up:<\/strong> Python uses True, False, None. C# uses True\/False. Copy-paste from either, and you&#8217;ve got a problem.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">9. Invalid Number Formats<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">JSON has strict rules about how numbers can be written, and several formats that look normal in code are actually invalid.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Broken:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>json\n{\n\u00a0\u00a0\"id\": 007,\n\u00a0\u00a0\"rate\": .5,\n\u00a0\u00a0\"balance\": 100.,\n\u00a0\u00a0\"code\": 0xFF\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s what&#8217;s wrong with each one:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>007 \u2014 leading zeros aren&#8217;t allowed (except for the number 0 itself, or decimals like 0.5)<\/li>\n\n\n\n<li>.5 \u2014 must be 0.5; the leading digit is required<\/li>\n\n\n\n<li>100. \u2014 must be 100 or 100.0; numbers can&#8217;t end in a dot<\/li>\n\n\n\n<li>0xFF \u2014 hex notation isn&#8217;t valid JSON<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Fix:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>json\n{\n\u00a0\u00a0\"id\": 7,\n\u00a0\u00a0\"rate\": 0.5,\n\u00a0\u00a0\"balance\": 100,\n\u00a0\u00a0\"code\": 255\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If you actually need to preserve leading zeros (like a phone number, ZIP code, or product SKU), store it as a string: &#8220;id&#8221;: &#8220;007&#8221;.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">10. Unexpected End of Input (Truncated JSON)<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Broken:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>json\n{\n\u00a0\u00a0\"name\": \"Alice\",\n\u00a0\u00a0\"items\": &#91;\"apple\", \"banana\",<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The string just&#8230; stops. No closing bracket, no closing brace. The parser hits the end of the file and says &#8220;wait, you weren&#8217;t done.&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This usually means one of three things:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Your API response was cut off mid-transfer<\/li>\n\n\n\n<li>You copied JSON from a console or log that truncated long output<\/li>\n\n\n\n<li>A file write didn&#8217;t complete<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Fix:<\/strong> Complete the structure.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>json\n{\n\u00a0\u00a0\"name\": \"Alice\",\n\u00a0\u00a0\"items\": &#91;\"apple\", \"banana\"]\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Pro tip:<\/strong> If you keep getting truncated JSON from an API, check the response headers for Content-Length and verify it matches what you actually received. Often the API isn&#8217;t broken \u2014 your network or proxy layer is silently chopping the response.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Bonus: Three Sneaky Issues That Aren&#8217;t on the Top 10 List<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These don&#8217;t show up on most &#8220;common JSON errors&#8221; articles, but they&#8217;ve burned plenty of developers.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Duplicate keys.<\/strong> Technically allowed by the JSON spec, but most parsers silently keep only the last value. So {&#8220;name&#8221;: &#8220;Alice&#8221;, &#8220;name&#8221;: &#8220;Bob&#8221;} becomes {&#8220;name&#8221;: &#8220;Bob&#8221;} \u2014 and you never know why your data looks wrong.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>BOM characters.<\/strong> Some text editors save files with an invisible byte-order mark at the start. Most JSON parsers choke on it. If your JSON looks perfect but refuses to parse, this is often the reason. Save the file as <strong>UTF-8 without BOM<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Hidden whitespace from copy-paste.<\/strong> Copying JSON from a PDF, Word doc, or Slack message often introduces non-breaking spaces (U+00A0) that look identical to normal spaces but break the parser. If your JSON works when you retype it but fails when pasted \u2014 this is why.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>The Fastest Way to Debug Any JSON Error<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When you&#8217;re stuck, here&#8217;s the four-step routine that&#8217;ll solve nearly any JSON problem:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>1. Paste your JSON into a validator.<\/strong><a href=\"https:\/\/json-beautifier.org\/\"> Ours<\/a> runs entirely in your browser, so your data never leaves your machine. It highlights the exact line and character where parsing breaks.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2. Read the error message literally.<\/strong> &#8220;Unexpected token } at position 47&#8221; means: at character 47, the parser found a } when it was expecting something else. Count to position 47, or just look at the highlighted spot.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>3. Format it first, then read it.<\/strong> Minified JSON hides errors. Beautified JSON exposes them. Get in the habit of running broken JSON through a<a href=\"https:\/\/json-beautifier.org\/\"> beautifier<\/a> before you even try to debug it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>4. Check the four most common culprits first:<\/strong> trailing commas, single quotes, missing commas between properties, and mismatched brackets. That covers 80% of JSON errors you&#8217;ll ever encounter.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">JSON errors are annoying, but they&#8217;re consistent. Once you&#8217;ve seen these ten patterns a few times, you&#8217;ll spot them in two seconds flat. Promise.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You&#8217;ve spent twenty minutes staring at a JSON file. Your API call keeps failing. The error message is some cryptic [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":135,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-131","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-json-beautifier"],"_links":{"self":[{"href":"https:\/\/json-beautifier.org\/blog\/wp-json\/wp\/v2\/posts\/131","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/json-beautifier.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/json-beautifier.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/json-beautifier.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/json-beautifier.org\/blog\/wp-json\/wp\/v2\/comments?post=131"}],"version-history":[{"count":3,"href":"https:\/\/json-beautifier.org\/blog\/wp-json\/wp\/v2\/posts\/131\/revisions"}],"predecessor-version":[{"id":134,"href":"https:\/\/json-beautifier.org\/blog\/wp-json\/wp\/v2\/posts\/131\/revisions\/134"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/json-beautifier.org\/blog\/wp-json\/wp\/v2\/media\/135"}],"wp:attachment":[{"href":"https:\/\/json-beautifier.org\/blog\/wp-json\/wp\/v2\/media?parent=131"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/json-beautifier.org\/blog\/wp-json\/wp\/v2\/categories?post=131"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/json-beautifier.org\/blog\/wp-json\/wp\/v2\/tags?post=131"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}