How to add dynamic JSON-LD product schema in Shopify?

Hi everyone,
I want to add JSON-LD Product Schema to my Shopify store so Google can show rich snippets (price, availability, and star ratings) in search results.
The problem is, most guides show how to generate static JSON-LD, which obviously doesn’t scale when you have hundreds of products. I really don’t want to install a heavy, paid SEO app just to inject a basic schema code, as I’m trying to keep my site speed fast and monthly expenses low.
Is there a way to write a dynamic Liquid code snippet that I can paste into my theme files once, and it automatically pulls the correct product titles, prices, variants, and review ratings for every product page?
Any help or clean code snippet would be highly appreciated! Thanks!

Have you looked for something like this? Add it to the bottom of your product template.

<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "Product",
  "name": {{ product.title | json }},
  "description": {{ product.description | strip_html | truncate: 500 | json }},
  "image": {{ product.featured_image | image_url: width: 1024 | json }},
  "brand": {
    "@type": "Brand",
    "name": {{ product.vendor | json }}
  },
  "sku": {{ product.selected_or_first_available_variant.sku | json }},
  "offers": [
    {% for variant in product.variants %}
    {
      "@type": "Offer",
      "name": {{ variant.title | json }},
      "price": {{ variant.price | money_without_currency | json }},
      "priceCurrency": {{ cart.currency.iso_code | json }},
      "availability": "https://schema.org/{% if variant.available %}InStock{% else %}OutOfStock{% endif %}",
      "url": "{{ shop.url }}/products/{{ product.handle }}?variant={{ variant.id }}"
    }{% unless forloop.last %},{% endunless %}
    {% endfor %}
  ]
}
</script>

Hi @grand_subaru ,

You absolutely don’t need a heavy paid app for this. You can easily do this using a single, dynamic Liquid snippet pasted into your theme’s layout file.
There is an amazing, 100% free tool that generates exactly this dynamic Liquid code for Shopify: Shopify Product Schema Generator — Dynamic JSON-LD (specifically their Shopify Product Schema generator).

Unlike static generators, this one builds a customized Liquid snippet that automatically maps Shopify’s global variables (like product.title, product.price, and variants) and outputs them in Google-ready JSON-LD format.

Thank You !

Hey @grand_subaru ,

You can create a dynamic JSON-LD schema using Shopify Liquid and add it once in your theme. It can automatically pull product data like:

product.title → Product name
product.price → Price
product.available → Availability
product.variants → Variant details

This will work across all product pages without creating separate schema for each product.

For star ratings you’ll need to connect your review app data since Shopify doesn’t provide rating information by default.

Have you already installed any review app for your store?

Thank You !

Thanks for the recommendation! I appreciate the suggestion. I’ll check out the Shopify Product Schema Generator and see if it fits what I’m looking for. If it can generate a dynamic Liquid snippet without needing a paid app, that sounds like exactly what I need.

Thanks for the help ! I really appreciate it

Thank you for the help I appreciate it !

Product Schema JSON-LD is usually automatically generated as part of the product information section, for each product page, exactly like you want it.

Generating product schema is a requirement for a theme to get accepted to the Theme Store, so you do not need to do anything if you’re using relatively modern theme from the store.

Your review app should store product rating in the predefined metafield, this way it will be included in this markup automatically.

If you’re concerned that your site does not have proper JSON-LD, share a link to your store.

You’re welcome! I hope it helps. If this solves your issue, I’d really appreciate it if you could mark my answer as the accepted solution. Thanks!