Fix the script tag contains invalid JSON that cannot be parsed

Here I will show how to fix an AMP Validator issue "the script tag contains invalid JSON that cannot be parsed".

You might face it while you are working on AMP implementation on your website and it looks like this in AMP validator:

The script tag contains invalid JSON that cannot be parsed in AMP validator

Unfortunately, the validator does only show that some error exists but does not show where and what.

In my case JSON looks like this:

{
 "@context": "http://schema.org",
 "@type": "NewsArticle",
 "mainEntityOfPage": {
   "@type": "WebPage",
   "@id": "https://hinty.io/ivictbor/importerror-cannot-import-name-uuid-generate-random/"
  },
 "headline": "ImportError: cannot import name _uuid_generate_random",
 "image": {
   "@type": "ImageObject",
   "url": "https://hinty.io/static/preview.9f29fd3723c1.jpg",
   "height": 800,
   "width": 800
 },
 "datePublished": "Dec. 9, 2016, 1:10 p.m.",
 "dateModified": "March 6, 2021, 6:20 p.m.",
 "author": {
   "@type": "Person",
   "name": "Ivan Borshchov"
 },
 "publisher": {
    "@type": "Person",
    "name": "Ivan Borshchov",
    "logo": {
      "@type": "ImageObject",
      "url": "https://lh3.googleusercontent.com/a-/AOh14GgC46Het22MT_a6gNE8_IxtdYupUNqwlxgxigLB6Q=s96-c",
      "width": 96,
      "height": 96
    }
  },
 "description": "If you have: ImportError: cannot import name _uuid_generate_random Possible you use: `kombu < 3.0.30` \+ `Python 2.7.11` If yes, this bug is fixed in new `ko..."
}

From first sight, it looks absolutely correct, but actually it is not.

The trick is to use https://jsonformatter.curiousconcept.com/ to test the JSON text:

Use JSON validator

Very important is to uncheck Fix JSON, otherwise, it can fix the issue and say it is valid (which was my case and I spent additional time because just saw a green VALID message🤯).

So For me, the issue was in an unescaped backslash:

Actual reason of error

And now it works without a warning:

Fixed

#amp #json
3
Ivan Borshchov profile picture
Mar 06, 2021
by Ivan Borshchov
Did it help you?
Yes !
No

Other by Ivan Borshchov