A Production-Ready JSON-LD Snippet for Shopify: Product, Offer, and AggregateRating


Shopify's default structured data is a decent start, but it's not enough to compete. It often fails on three critical points:
Variant Offers: It doesn't properly list each variant as a separate
Offer
, meaning Google doesn't see the specific availability (InStock
/OutOfStock
) or pricing for your different sizes or colors.AggregateRating: It almost never integrates correctly with your review app out-of-the-box, robbing you of the chance to earn star ratings in search results.
Missing Identifiers: Important fields like
sku
,gtin
, andmpn
are frequently omitted.
This isn't just a minor issue—it directly impacts your visibility and click-through rate.
Here’s the solution: a single, robust Liquid snippet that handles everything. This code generates a complete JSON-LD script that correctly formats Product
, Offer
(for every variant), and AggregateRating
data.
The Code: json-ld-product.liquid
This is the complete snippet. It intelligently builds the JSON-LD by checking for the existence of data before printing it.
{% comment %}
File: snippets/json-ld-product.liquid
Author: GetEcomTools.com
Purpose: Generate a complete and robust JSON-LD script for Product pages,
including all variants as Offers and integrating with review metafields.
{% endcomment %}
{%- assign current_variant = product.selected_or_first_available_variant -%}
{%- assign product_image = product.featured_image | default: product.images.first -%}
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Product",
"name": {{ product.title | json }},
"url": {{ shop.url | append: product.url | json }},
{%- if product_image -%}
"image": {{ product_image | image_url: width: 1200 | prepend: "https:" | json }},
{%- endif -%}
"description": {{ product.description | strip_html | strip_newlines | truncate: 5000 | json }},
{%- if current_variant.sku != blank -%}
"sku": {{ current_variant.sku | json }},
{%- endif -%}
{%- if current_variant.barcode != blank -%}
"gtin13": {{ current_variant.barcode | json }},
{%- endif -%}
"brand": {
"@type": "Brand",
"name": {{ product.vendor | json }}
},
"offers": [
{%- for variant in product.variants -%}
{
"@type": "Offer",
"url": {{ shop.url | append: variant.url | json }},
{%- if variant.sku != blank -%}
"sku": {{ variant.sku | json }},
{%- endif -%}
{%- if variant.barcode != blank -%}
"gtin13": {{ variant.barcode | json }},
{%- endif -%}
"price": "{{ variant.price | divided_by: 100.00 }}",
"priceCurrency": {{ cart.currency.iso_code | json }},
"availability": "https://schema.org/{% if variant.available %}InStock{% else %}OutOfStock{% endif %}",
"itemCondition": "https://schema.org/NewCondition"
}{% unless forloop.last %},{% endunless %}
{%- endfor -%}
]
{% comment %}
IMPORTANT: This part assumes your review data is in metafields.
Adjust 'product.metafields.reviews.rating.value' and 'review_count'
to match the metafields from your review app (e.g., Loox, Yotpo, Judge.me).
{% endcomment %}
{%- if product.metafields.reviews.rating.value and product.metafields.reviews.review_count.value -%}
,"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": "{{ product.metafields.reviews.rating.value }}",
"reviewCount": "{{ product.metafields.reviews.review_count.value }}"
}
{%- endif -%}
}
</script>
How to Implement (3 Steps)
Create the Snippet: In your Shopify theme editor (
Online Store
>Themes
>...
>Edit code
), go to theSnippets
folder and click "Add a new snippet". Name it exactlyjson-ld-product.liquid
.Paste the Code: Copy the entire code block above and paste it into your new snippet file. Save.
Render in
theme.liquid
: Open your main layout file,layout/theme.liquid
. Find the closing</head>
tag. Just before it, add this code:{%- if template.name == 'product' -%} {%- render 'json-ld-product' -%} {%- endif -%}
This ensures the script only runs on product pages, where it's needed. Remember to find and remove any other product schema scripts in your theme to avoid errors.
How to Test It
Don't skip this. After implementing, go to one of your product pages and copy the URL.
Go to the Google Rich Results Test.
Paste your URL and run the test.
You should see a valid "Product" item detected. Click into it to inspect the details. Verify that your review scores and all product variants are listed correctly.
This one optimization provides search engines with the high-quality, structured information they need to feature your products more prominently.
Building a high-performance ecommerce store requires the right strategy and the right tools. This guide is just one piece of a much larger puzzle. At GetEcomTools.com, we specialize in deep-dive analysis, unbiased reviews, and actionable optimizations for serious online sellers. We cut through the marketing noise to help you find the software that will actually grow your business.
For more expert guides and data-driven tool comparisons, visit us at:
https://getecomtools.com
Subscribe to my newsletter
Read articles from GetEcomTools directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

GetEcomTools
GetEcomTools
In e-commerce, the right tools make all the difference. But with thousands of options available, finding the software that will actually improve your SEO, streamline your operations, and boost your bottom line is a constant challenge. Marketing claims are loud, but real-world results are what matter. GetEcomTools.com was created to cut through that noise. We are your definitive resource for navigating the complex world of e-commerce tools. Our mission is simple: to provide clear, unbiased, and expert-driven guidance that helps you make smarter technology decisions for your online store. Our process combines rigorous hands-on testing with deep, data-driven analysis. We vet hundreds of tools to identify the solutions that truly deliver on their promises. From foundational platforms to niche apps, we provide in-depth reviews, direct comparisons, and actionable insights focused on tangible outcomes. We specialize in the key pillars of e-commerce success: SEO & Performance: Discover the tools you need to rank higher, improve site speed, and build a strong technical foundation for organic growth. Conversion Rate Optimization: Find proven solutions for page building, A/B testing, user reviews, and checkout enhancements that turn more visitors into customers. Store Operations: Streamline your business with the best tools for inventory management, shipping, fulfillment, and customer support. Marketing & Growth: Master your marketing with top-tier apps for email, SMS, loyalty programs, and advertising that drive real results. Stop wasting time and money on ineffective software. Let GetEcomTools.com be your guide to building a more powerful, optimized, and profitable e-commerce business.