JSON metafield through liquid

Solved

JSON metafield through liquid

Pndiongue
Visitor
3 1 0

Hello,

 

I am trying to print out values from a JSON metafield but it does not work:

 

-JSON Schema : 

 

{
"type": "array",
"items": {
"type": "object",
"properties": {
"license_id": {
"type": "string",
"description": "Unique ID of the license"
},
"product_name": {
"type": "string",
"description": "The name of the purchased product"
},
"expiry_date": {
"type": "string",
"format": "date",
"description": "The expiration date of the license (YYYY-MM-DD)"
}
},
"required": [
"license_id",
"product_name",
"expiry_date"
]
}
}

 

-Customer JSON values:

 

[
{
"license_id": "12345",
"product_name": "Luminary Loud Pro",
"expiry_date": "2026-01-01"
},
{
"license_id": "67890",
"product_name": "Luminary Loud Enterprise",
"expiry_date": "2027-05-15"
}
]

 

Liquid :

 

{% assign licenses = customer.metafields.custom.purchased_license_record %}

{% if licenses != blank %}
<table>
<tr>
<th>License ID</th>
<th>Product</th>
<th>Expiry Date</th>
</tr>
{% for license in licenses %}
<tr>
<td>{{ license.license_id }}</td>
<td>{{ license.product_name }}</td>
<td>{{ license.expiry_date }}</td>
</tr>
{% endfor %}
</table>
{% else %}
<p>No licenses found.</p>
{% endif %}

Accepted Solution (1)

Pndiongue
Visitor
3 1 0

This is an accepted solution.

Never mind !! Just add ".value" to "purchased_license_record" then I should be fine 🙂

View solution in original post

Reply 1 (1)

Pndiongue
Visitor
3 1 0

This is an accepted solution.

Never mind !! Just add ".value" to "purchased_license_record" then I should be fine 🙂