FROM CACHE - en_header

Problem with new metafield type `json`

Solved
skraloupak
Shopify Partner
13 3 2

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
Accepted Solutions (2)

Accepted Solutions
skraloupak
Shopify Partner
13 3 2

This is an accepted solution.

skraloupak
Shopify Partner
13 3 2

This is an accepted solution.

Sorry for that. Solution by 

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'] }}

View solution in original post

Replies 3 (3)
skraloupak
Shopify Partner
13 3 2

This is an accepted solution.

solved

DanWG
Shopify Partner
2 0 0

what was the solution????

skraloupak
Shopify Partner
13 3 2

This is an accepted solution.

Sorry for that. Solution by 

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'] }}