4

I would like to present a book in both paperback and ebook format with JSON-LD.

When I'm adding another mainEntity, the structured data testing tool finds a duplicate key:

            <script type="application/ld+json">
            {
                  "@context": "http://schema.org",
                  "@type": "WebPage",
                  "mainEntity":{
                          "@type": "Book",
                          "author": "http://mywebsite.com/authors",
                          "bookFormat": "http://schema.org/EBook",
                          "datePublished": "2017-08-26",
                          "image": "http://mywebsite.com/images/coverImage.jpg",
                          "inLanguage": "en-US",
                          "isbn": "ebook isbn",
                          "name": "my website",
                          "numberOfPages": "200",
                          "offers": {
                            "@type": "Offer",
                            "availability": "http://schema.org/InStock",
                            "price": "30",
                            "priceCurrency": "USD"
                          },
                  "mainEntity":{
                          "@type": "Book",
                          "author": "http://mywebsite.com/authors",
                          "bookFormat": "http://schema.org/Paperback",
                          "datePublished": "2017-08-26",
                          "image": "http://mywebsite.com/images/coverImage.jpg",
                          "inLanguage": "en-US",
                          "isbn": "book isbn",
                          "name": "my website",
                          "numberOfPages": "200",
                          "offers": {
                            "@type": "Offer",
                            "availability": "http://schema.org/InStock",
                            "price": "55",
                            "priceCurrency": "USD"
                          },
                          "publisher": "Publisher name",
                        }
                }
            </script>

Could you please tell me the best way to implement it?

unor
  • 92,415
  • 26
  • 211
  • 360
laurent
  • 41
  • 2

1 Answers1

1

If you have multiple values for a property, you have to use one property with an array value (with []) instead of repeating the property:

<script type="application/ld+json">
  {
    "@context": "http://schema.org",
    "@type": "WebPage",
    "mainEntity": 
    [
      {
        "@type":"Book"
      },
      {
        "@type":"Book"
      }
    ]
  }
</script>
unor
  • 92,415
  • 26
  • 211
  • 360