jsonshopifyliquid

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?


Solution

  • 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 }}