Google Issues with ld+json

Topic summary

A user is encountering two Google-related errors in their Shopify product structured data (ld+json):

Error 1: Parsing error near {% for image in product.images %}

  • Caused by improper JSON syntax when Liquid loops generate output
  • Trailing commas after the last array item break JSON validation
  • Solution: Wrap the image loop in a conditional check ({% if product.images.size > 0 %}) and ensure proper comma placement

Error 2: Missing required fields (“offers”, “review”, or “aggregateRating”)

  • Google requires at least one of these fields in Product schema
  • The user has these fields, but conditional logic may prevent them from rendering
  • Additional issues identified:
    • Trailing comma after the “size” field before the closing brace (invalid JSON)
    • Extra space in the return policy URL that could break parsing

Recommended fixes:

  • Remove trailing commas before closing braces
  • Add conditional guards around optional fields
  • Clean up URL formatting

A detailed code correction was provided by a Shopify solutions expert.

Summarized with AI on October 29. AI used: claude-sonnet-4-5-20250929.

I am having some issues raised with Google. I keep having the following issue: Parsing error: Missing ‘}’ or object member name, specifically highlighted around the line in bold: {% for image in product.images %}.

I am also have a product snippet issue for Either “offers”, “review”, or “aggregateRating” should be specified.

would appreciate any help/suggestions.
below is my ld+json:

Hi @avk9641

I am from Mageplaza - Shopify solution expert.

Problem 1: Parsing Error: Missing ‘}’ or object member name
The root cause is because Liquid loops (like {% for image in product.images %}) are outputting inside JSON directly without ensuring valid JSON syntax.

In JSON, you can’t have trailing commas after the last item.
If your {% for image in product.images %} loop outputs an extra comma, Google and other parsers will throw errors.

Your section:

"image": [
{% for image in product.images %}
"{{ image.src | img_url: '1024x1024' }}"{% unless forloop.last %},{% endunless %}
{% endfor %}
],

is mostly correct, but outside of context, if product.images is empty, it could still cause syntax issues.

SOLUTION:

  • Make sure to only output this if there are images.
  • Also, you need to guard it better.

Here’s a safer way:

{% if product.images.size > 0 %}
"image": [
{% for image in product.images %}
"{{ image.src | img_url: '1024x1024' }}"{% unless forloop.last %},{% endunless %}
{% endfor %}
],
{% endif %}

Important: notice the comma after the array ], — this needs to be carefully placed.
If no images, you don’t want image: appearing incorrectly.

Problem 2: Missing “offers”, “review”, or “aggregateRating”
Google requires that at least one of these fields exists in the Product schema:

  • “offers”
  • “review”
  • “aggregateRating”

You have them in your code…
BUT the problem is:

You are wrapping “aggregateRating” and “review” inside {% if … %}, so if there are no reviews, that part won’t be rendered at all.

And offers is always there, but if any Liquid errors cause syntax invalidation (e.g., broken commas or quotes), Google will not see it properly.

Hidden Problems in Your Code:

  • You have a trailing comma before the closing } of the Product object.
    Example:
"size": "{{ product.options_by_name['Size'].values | first }}",
}
​

JSON must NOT have a trailing comma before the last }.
➔ Remove that final comma after “size”!

  • There’s an unnecessary space in your Return Policy URL:
"url": "https://merhoki.com/policies/ ",
​

That space could break parsing. Remove it.

So, fixed version (partial), focusing on critical points:


Please let me know if it works as expected!

Best regards