2

I hag a previous JSON-LD tag on my products page, which worked well (no errors, and 3 warnings in Google's Structured Data Testing Tool).

<script type="application/ld+json">
        {
            "@context": "https://schema.org/",
            "@type": "Product",
            "name": "My product name",
            "description": "My product description",
            "image": [
                "https://link.to/my/image_1.jpg",
                "https://link.to/my/image_2.jpg",
                "https://link.to/my/image_3.jpg"
            ],
            "sku": "00000100000",
            "brand": {
                "@type": "Thing",
                "name": "BRANDNAME"
            },
            "offers": {
                "@type": "Offer",
                "url": "https://link.to/my/product/id",
                "priceCurrency": "EUR",
                "price": "249.90",
                "itemCondition": "https://schema.org/NewCondition",
                "availability": "https://schema.org/InStock"
            },
            "reviews": [
                {
                    "@type": "Review",
                    "datePublished": "2019/03/19",
                    "name": "Very nice product",
                    "reviewBody": "Very nice product \r\nI mean it",
                    "reviewRating": {
                        "@type": "Rating",
                        "ratingValue": 5,
                        "bestRating": 5,
                        "worstRating": 1
                    },
                    "author": {
                        "@type": "Person",
                        "name": "ClientPseudo"
                    }
                }
            ],
            "aggregateRating": {
                "@type": "AggregateRating",
                "ratingValue": "5",
                "reviewCount": 1,
                "bestRating": 5,
                "worstRating": 1
            }
        }
</script>

I tried to add breadcrumb by moving my Product content into the mainEntity of an ItemPage type as suggested here, but the tool does not display any warning anymore.

<script type="application/ld+json">
        {
            "@context": "https://schema.org/",
            "@type": "ItemPage",
            "mainEntity": {
                "@type": "Product",
                "name": "My product name",
                "description": "My product description",
                "image": [
                    "https://link.to/my/image_1.jpg",
                    "https://link.to/my/image_2.jpg",
                    "https://link.to/my/image_3.jpg"
                ],
                "sku": "00000100000",
                "brand": {
                    "@type": "Thing",
                    "name": "BRANDNAME"
                },
                "offers": {
                    "@type": "Offer",
                    "url": "https://link.to/my/product/id",
                    "priceCurrency": "EUR",
                    "price": "249.90",
                    "itemCondition": "https://schema.org/NewCondition",
                    "availability": "https://schema.org/InStock"
                },
                "reviews": [
                    {
                        "@type": "Review",
                        "datePublished": "2019/03/19",
                        "name": "Very nice product",
                        "reviewBody": "Very nice product \r\nI mean it",
                        "reviewRating": {
                            "@type": "Rating",
                            "ratingValue": 5,
                            "bestRating": 5,
                            "worstRating": 1
                        },
                        "author": {
                            "@type": "Person",
                            "name": "ClientPseudo"
                        }
                    }
                ],
                "aggregateRating": {
                    "@type": "AggregateRating",
                    "ratingValue": "5",
                    "reviewCount": 1,
                    "bestRating": 5,
                    "worstRating": 1
                }
            },
            "breadcrumb": {
                "@type": "BreadcrumbList",
                "itemListElement": [
                    {
                        "@type": "ListItem",
                        "position": 1,
                        "item": {
                            "@id": "/",
                            "name": "Home"
                        }
                    },
                    {
                        "@type": "ListItem",
                        "position": 2,
                        "item": {
                            "@id": "/myCategory",
                            "name": "My Category"
                        }
                    },
                    {
                        "@type": "ListItem",
                        "position": 3,
                        "item": {
                            "@id": "/mySubCategory",
                            "name": "My subcategory"
                        }
                    }
                ]
            }
        }
</script>

How can I make sure my code is valid?

2 Answers 2

1

Your markup is valid. But if you move Product from the top level to bottom the testing tool suppresses warnings.

Look into page with http://linter.structured-data.org/ - everything is on the place.

If you really-really want to see warnings by testing tool, so use an opposite type to mainEntitymainEntityOfPage, like in example below, which is valid AND lets the testing tools display warnings, because the Product type remains on the top level:

    <script type="application/ld+json">
        {
            "@context": "https://schema.org/",
            "@type": "Product",
            "name": "My product name",
            "description": "My product description",
            "image": [
                "https://link.to/my/image_1.jpg",
                "https://link.to/my/image_2.jpg",
                "https://link.to/my/image_3.jpg"
            ],
            "sku": "00000100000",
            "brand": {
                "@type": "Thing",
                "name": "BRANDNAME"
            },
            "offers": {
                "@type": "Offer",
                "url": "https://link.to/my/product/id",
                "priceCurrency": "EUR",
                "price": "249.90",
                "itemCondition": "https://schema.org/NewCondition",
                "availability": "https://schema.org/InStock"
            },
            "reviews": [
                {
                    "@type": "Review",
                    "datePublished": "2019/03/19",
                    "name": "Very nice product",
                    "reviewBody": "Very nice product \r\nI mean it",
                    "reviewRating": {
                        "@type": "Rating",
                        "ratingValue": 5,
                        "bestRating": 5,
                        "worstRating": 1
                    },
                    "author": {
                        "@type": "Person",
                        "name": "ClientPseudo"
                    }
                }
            ],
            "aggregateRating": {
                "@type": "AggregateRating",
                "ratingValue": "5",
                "reviewCount": 1,
                "bestRating": 5,
                "worstRating": 1
            },
            "mainEntityOfPage":{
            "@type": "ItemPage",
            "@id": "https://link.to/my/product/id",
             "breadcrumb": {
                "@type": "BreadcrumbList",
                "itemListElement": [{
    "@type": "ListItem",
    "position": 1,
    "name": "Books",
    "item": "https://example.com/books"
  },{
    "@type": "ListItem",
    "position": 2,
    "name": "Authors",
    "item": "https://example.com/books/authors"
  },{
    "@type": "ListItem",
    "position": 3,
    "name": "Ann Leckie",
    "item": "https://example.com/books/authors/annleckie"
  },{
    "@type": "ListItem",
    "position": 4,
    "name": "Ancillary Justice",
    "item": "https://example.com/books/authors/ancillaryjustice"
  }]
}
            }
            }
        }
</script>
0

Thanks to this answer on stackOverflow, I was able to create a code which worked for both a product and a breadcrumb, using a named graph array :

<script type="application/ld+json">
               {
            "@context": "https://schema.org/",
            "@type": "ItemPage",
            "@graph": [
                {
                    "@type": "Product",
                    "name": "My product name",
                    "description": "My product description",
                    "image": [
                        "https://link.to/my/image_1.jpg",
                        "https://link.to/my/image_2.jpg",
                        "https://link.to/my/image_3.jpg"
                    ],
                    "sku": "00000100000",
                    "brand": {
                        "@type": "Thing",
                        "name": "BRANDNAME"
                    },
                    "offers": {
                        "@type": "Offer",
                        "url": "https://link.to/my/product/id",
                        "priceCurrency": "EUR",
                        "price": "249.90",
                        "itemCondition": "https://schema.org/NewCondition",
                        "availability": "https://schema.org/InStock"
                    },
                    "reviews": [
                        {
                            "@type": "Review",
                            "datePublished": "2019/03/19",
                            "name": "Very nice product",
                            "reviewBody": "Very nice product \r\nI mean it",
                            "reviewRating": {
                                "@type": "Rating",
                                "ratingValue": 5,
                                "bestRating": 5,
                                "worstRating": 1
                            },
                            "author": {
                                "@type": "Person",
                                "name": "ClientPseudo"
                            }
                        }
                    ],
                    "aggregateRating": {
                        "@type": "AggregateRating",
                        "ratingValue": "5",
                        "reviewCount": 1,
                        "bestRating": 5,
                        "worstRating": 1
                    }
                },
                {
                    "@type": "BreadcrumbList",
                    "itemListElement": [
                        {
                            "@type": "ListItem",
                            "position": 1,
                            "item": {
                                "@id": "/",
                                "name": "Home"
                            }
                        },
                        {
                            "@type": "ListItem",
                            "position": 2,
                            "item": {
                                "@id": "/myCategory",
                                "name": "My Category"
                            }
                        },
                        {
                            "@type": "ListItem",
                            "position": 3,
                            "item": {
                                "@id": "/mySubCategory",
                                "name": "My subcategory"
                            }
                        }
                    ]
                }
            ]
        }
    </script>
1
  • 1
    Watch out with these fancy solutions. They may be technically correct, but what is important is that the systems you want to read them can understand it. If you are going to go off the beaten track, test. And test not only with Google tools but others that are important. e.g. Bing. Mar 26, 2019 at 12:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.