Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Safari throws when parsing JSON-LD

Create an HTML file with this simple code and open it in Safari.

<html>
  <head>
    <script type="application/ld+json">
      [
        {
          "@context": "http://schema.org",
          "@type": "Organization",
          "name": "Parqet",
          "url": "https://www.parqet.com/",
          "logo": "https://www.parqet.com/logos/parqet_logo_pos.svg",
          "sameAs": [
            "https://www.facebook.com/parqetcom",
            "https://twitter.com/ParqetApp",
            "https://www.instagram.com/ParqetApp/",
            "https://www.youtube.com/channel/UC4LOcElG8Z73Hvgbbp3m1KQ",
            "https://www.linkedin.com/company/parqet/",
            "https://github.com/tresorone"
          ]
        }
      ]
    </script>
  </head>
  <body>
    test
  </body>
</html>

Safari will produce this error.

TypeError: undefined is not an object (evaluating 'r["@context"].toLowerCase')

enter image description here

Any insight into how we could fix that is greatly appreciated. Adding a trailing comma to the last property or object removes the error - but it's not valid JSON anymore.

like image 727
ProblemsOfSumit Avatar asked Nov 29 '25 16:11

ProblemsOfSumit


1 Answers

Looks like Safari has a problem with the Array and wants an Object instead. To still write multiple JSON-LD definitions, we can use the @graph notation.

This fixes the error.

<html>
  <head>
    <script type="application/ld+json">
      {
        "@context": "http://schema.org",
        "@graph": [
          {
            "@type": "Organization",
            "name": "Parqet",
            "url": "https://www.parqet.com/",
            "logo": "https://www.parqet.com/logos/parqet_logo_pos.svg"
          }
        ]
      }
    </script>
  </head>
  <body>
    test
  </body>
</html>

To be clear: an Array of Objects is perfectly valid. I suspect this is a bug in Safari.

like image 159
ProblemsOfSumit Avatar answered Dec 01 '25 13:12

ProblemsOfSumit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!