How to automatically change Metafields value_type from string to JSON_string?

hanka7n
New Member
1 0 0

Hello,

I have a question regarding the metafields. Is there a way a change the value_type from string to JSON_string using Liquid syntax? I know there are apps that can handle this but I would have to change it manually for every customer. 

It would be great to handle this from the code, that would either

A) change the value_type from string to JSON_string 

or

B) convert the string value to JSON_string format 

The reason why I need JSON_string is to be able to access the information. 

{{ customer.metafields.global.ci_plus["company_name"] }}  

output: Testing company

This doesn't work with string type.

Thank you!  

 

 

"metafields": [
{
"id": 188214304114,
"namespace": "global",
"key": "ci_plus",
"value": "{\"company_name\":\"Testing Company\",\"company_id\":\"1234\",\"company_tax_id\":\"CZ57690\"}",
"value_type": "string",
"description": null,
"owner_id": 0,
"created_at": "2021-03-05T12:06:44+01:00",
"updated_at": "2021-03-05T13:06:32+01:00",
"owner_resource": "customer"
}
]

 

 

 

 

 

 

0 Likes