Dispaly the contets of json metafield in main-order.liquid

Topic summary

A developer is attempting to display JSON metafield data from an order in Shopify’s main-order.liquid template but encountering parsing issues.

The Problem:

  • A JSON metafield (order.metafields.xchange.licenses) added by an app displays correctly in checkout scripts
  • In main-order.liquid, the metafield appears as a string rather than parsed JSON
  • The for loop doesn’t iterate over the data, preventing the table from rendering properly

Current Behavior:

  • When displayed directly using {{ order.metafields.xchange.licenses }}, the raw JSON string appears
  • The data structure contains product information with fields: product, serial, and download

What Works vs. What Doesn’t:

  • ✓ Metafield displays successfully in checkout scripts
  • ✗ Same code fails to parse/loop in main-order.liquid

The developer suspects the metafield is being converted to a string in this context and seeks advice on how to properly parse and iterate over the JSON data in the order template.

Summarized with AI on November 18. AI used: claude-sonnet-4-5-20250929.

Hi Guys
I have a json metafield added to orders by an app and it’s easy to display it’s contents in the checkout scripts for example so I know it works. But in main-order.liquid I can see it’s contents as string but it does not parse as json and I’m not able to show it in the same way. Any idea?

Here is the code:

{% if order.metafields.xchange.licenses %}  
<table BORDER=”1″ >
	<thead>
		<tr style="background-color:#f0f0f0">
			<th style="text-align:left; padding-left: 5px;">Product</th>
			<th style="text-align:left">Serial</th>
			<th style="text-align:left">Download</th>
		</tr>
	</thead>
    <tbody>
		{% for license in order.metafields.xchange.licenses %}
			<tr>
				<td style="text-align:left; padding-left: 5px;">{{license.product}}</td>
				<td style="text-align:left">{{license.serial}}</td>
				<td style="text-align:left"><a href="{{license.download}}">{{license.download}}</a></td>
			</tr>
		{% endfor %}
	</tbody>
</table>
{% else %}
<strong>Please wait while we generate your license key </strong><br>
You may need to refresh the browser page (F5)
<br><br>
{% endif %}

Here is how it looks like when it working:

Product Serial Download

Test Product DUMMY_LICENSE_638270898649923327 https://koolsoftware.com/activate/®

Now in main-order.liquid if I dispaly it like this:

{{ order.metafields.xchange.licenses }}

It looks:

[{“product”:“Test Product”,“serial”:“DUMMY_LICENSE_638270898649923327”,“download”:“https://koolsoftware.com/activate/®”}]

But the same code above does not print the table and never goes into the ‘for’ loop. I’m guessing it turned into a ‘string’ but it makes no sense to me.

Any advice?