Abid Hasan
Abid Hasan

Reputation: 57

Accessing JSON's value from app metafield in liquid

Here's my sample JSON,

{
  car: {
    color: 'Red'
  },
  train: {
    color: 'Blue'
  }
}

I have added my JSON using metafieldsSet mutation. What I want to access is car's color or train's color from that metafield. But, doing {{ app.metafields.namespace.key.car }} returns null. Is this doable? If so, what am I missing?

Upvotes: 0

Views: 67

Answers (1)

Zeindelf
Zeindelf

Reputation: 86

You'll need access value first

{% assign metafield_value = app.metafields.namespace.key.value %}

Then, get json value as needed

{{ metafield_value.car.color }}

Or access directly if you don't wanna use variables

{{ app.metafields.namespace.key.value.car.color }}

Upvotes: 1

Related Questions