I am attempting to expose product-specific JSON metafields (custom.key_benefits_json and custom.key_ingredients_json) within my theme’s Schema.org Product structured data, located in sections/main-product.liquid. The goal is to make this data readable by search engine bots for SEO purposes.
Issue: Despite multiple attempts using various Liquid coding patterns, Google’s Rich Results Test consistently reports an “Unparsable structured data” error with the specific detail: “Parsing error: Missing ‘,’ or ‘]’ in array declaration.” This indicates that the generated JSON output for the additionalProperty array is malformed.
Details of the Metafields:
- Type: Both are JSON metafields.
- Structure: Each metafield contains an array of objects, where each object has
nameanddescriptionkeys (e.g.,[{"name":"Benefit Name","description":"Benefit Description"}, ...]).
Troubleshooting Steps Taken: I’ve attempted several robust Liquid coding strategies to generate this JSON array, including:
- Direct String Appending with
is_first_itemflag:
- This involved initializing an empty string and then
appending JSON object strings, carefully managing commas using a boolean flag (is_first_itemoritem_counter) to ensure commas only appear between items. - This approach was expected to produce valid JSON, but the Google Rich Results Test still reported the parsing error.
- Using
| jsonfilter for content values:
- Recognizing that
| escapemight not be sufficient for JSON, I switched to using the| jsonfilter on theitem.nameanditem.descriptionvalues (e.g.,item.name | json) to ensure they are properly JSON-escaped and quoted. This also required removing literal quotes from the JSON object string. - This resolved previous Liquid editor syntax errors (
Expected dotdot,Unexpected character {), indicating the Liquid code itself became valid, but the output JSON still failed Google’s parser with the same "Missing ‘,’ or ‘]’ " error.
- Using
{% capture %}for array content:
- The most recent attempt involved using the
{% capture %}Liquid tag to build the entireadditionalPropertyarray content as a single string. This approach bypasses intermediateassign | appendchains, directly printing JSON object fragments and comma logic into thecaptureblock. - The captured string is then outputted with
| strip_newlines. - Despite this being the most robust method for complex JSON generation in Liquid, the Google Rich Results Test still reports the same
Parsing error: Missing ',' or ']' in array declaration.
Request: Given the persistence of this specific JSON parsing error from Google’s tool, despite using the most common and robust Liquid patterns for JSON generation (including proper comma handling and JSON escaping of values), I suspect there might be:
- An extremely subtle interaction with my theme’s Liquid parser or its output.
- A specific character or edge case in the metafield data itself that
| jsonisn’t fully resolving in this context. - An underlying issue with how the theme processes Liquid within
<script type="application/ld+json">blocks.
Could you please investigate why the generated JSON output for additionalProperty continues to be malformed according to Google’s Rich Results Test? I can provide the exact Liquid code snippet I’m using if needed, as well as access to the Shopify admin if required for debugging.
Thank you for your assistance.