Problem with new metafield type `json`

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

solved

what was the solution???

Sorry for that. Solution by Robert_Kanaan


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

{% assign doctor = product.metafields.vendor.house-doctor.value  %}        
<ul>
   {% for key_value in doctor %}
   <li>
      {{ key_value[0] }}: {{ key_value[1] }}
   </li>
   {% endfor %}
</ul>

Copy

Or access the key value directly:

{{ doctor['sustainability'] }}
1 Like