We spoke to a client on Friday morning who had noticed a new warning in Search Console, "The script tag contains invalid JSON that cannot be parsed." The affected pages had jumped from zero to 5,560 overnight, and by the following day had jumped to 17,526.


While the pages are displaying as "Valid with warnings" rather than errors, the client was rightfully concerned.

We investigated the issue, and noticed that the validator wasn't able to highlight the invalid JSON when we inspected the URLs being flagged with warnings. Our interpretation was that these warnings were being caused by a bug in the validator, rather than something that needed to be addressed by the client.

Weston Ruter from the AMP team at Google has identified the issue as newlines being interpreted by the validator as invalid JSON.

So the fix is trivial. Where you might have something like this:

<amp-analytics type="gtag" data-credentials="include">
  <script type="application/json">
      "vars" : {
        "gtag_id": "UA-123456-1"

Change it to something like this:

<amp-analytics type="gtag" data-credentials="include"><script type="application/json">{ "vars" : { "gtag_id": "UA-123456-1" } }</script></amp-analytics>

If you're using the AMP plugin for WordPress, he also posted a gist with the source code for a plugin which addresses the issue.

We've helped two publishers quickly test, launch and monetize AMP versions of their news sites, using a CMS-agnostic platform we built to automate much of the process. If you'd like to know more about it, get in touch with us using the form below.