How can I retrieve the value of specific product metafields?

i have added metafields to products and in that i have added goldpurity and diamondweight to which i am giving values as 18KT and 0.23c.

but when i am tying to retieve the value with {{ product.metafields.custom.goldpurity}} or {{ product.metafields.custom.goldpurity.value }} it shows me

{“type”:“root”,“children”:[{“type”:“paragraph”,“children”:[{“type”:“text”,“value”:“18KT”}]}]}

i want to retrieve 18KT value

It looks like the values are being stored as JSON objects. You should still be able to access them like this:

{% assign goldpurity_json = product.metafields.custom.goldpurity %}
{% assign goldpurity_parsed = goldpurity_json | parse_json %}
{% assign goldpurity_value = goldpurity_parsed.children[0].children[0].value %}
{{ goldpurity_value }}

I’m not sure what method you’re using to add the values or if they’ve all already been added, but you may want to consider storing them as plain text instead as it’s simpler.

I have tried this too but it displays nothing

I stored them as a single line text

{% assign metafield = product.metafields.custom.goldpurity.value %}
{% if metafield %}

{{ metafield }}

{% endif %}

hee is the solution