Subject: Persistent JSON Metafield Structured Data Parsing Error in sections/main-product.liquid

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 name and description keys (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:

  1. Direct String Appending with is_first_item flag:
  • This involved initializing an empty string and then appending JSON object strings, carefully managing commas using a boolean flag (is_first_item or item_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.
  1. Using | json filter for content values:
  • Recognizing that | escape might not be sufficient for JSON, I switched to using the | json filter on the item.name and item.description values (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.
  1. Using {% capture %} for array content:
  • The most recent attempt involved using the {% capture %} Liquid tag to build the entire additionalProperty array content as a single string. This approach bypasses intermediate assign | append chains, directly printing JSON object fragments and comma logic into the capture block.
  • 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 | json isn’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.

Hey @Melissa_Andrews,
I’d take you up on seeing the code snippet and/or accessing the store. So that we can check in more details the current approach and what might need to be updated.

Cheers!