How can I manipulate the new 'json' metafield type in liquid?

Hello,

i have problem, when i want to create new metafield with type json

{ "metafield":{ "key": "house-doctor", "namespace":"vendors", "value":"{\"nationality\":null,\"sustainability\":true}", "type":"json" } }

This create new metafield with json, but i can’t manipulate with him in liquid. When i print this value in liquid i see this: {“nationality”:null,“sustainability”:true}. But i can’t use him `

{% assign vendorData = shop.metafields.vendors[ ‘house-doctor’ ] %}`

{{vendorData.sustainability}}.

Old api with value_type works good. When i print value in liquid, looks different: {“nationality”=>nil, “sustainability”=>true}

{ "metafield":{ "key": "house-doctor", "namespace":"vendors", "value":"{\"nationality\":null,\"sustainability\":true}", "value_type":"json_string" } }

Does anyone have any advice? I dont want use any hack, etc. script.

Thanks

Here’s a couple of ways to access the values:

{% assign doctor = product.metafields.vendor.house-doctor.value  %}        

   {% for key_value in doctor %}
   - {{ key_value[0] }}: {{ key_value[1] }}
   
   {% endfor %}

Or access the key value directly:

{{ doctor['sustainability'] }}

Ou, there is .value after object. :flushed_face:

Thank you so much, works perfect!

Your welcome!