Why does using 'json' type in Metafield cause an error?

Why does using 'json' type in Metafield cause an error?

pushdaddy
Shopify Partner
17 0 1

we tried to migrate from `Metafield.valueType` to Metafield.type

but when we use type="json" as per this article

https://shopify.dev/apps/metafields/types

 

we get error

{
  "metafields": {
    "shop": "testsite.myshopify.com",
    "settings": {"error":"json not allowed for this object"},
    "moneyFormat": "\u003cspan class=money\u003eRs. {{amount}}\u003c\/span\u003e"
  }
}

 any idea to resolve will be great

we were using Metafield->put

 

it works fine with 

      "type" => "json_string"

but

     "type" => "json"

does not work

Replies 3 (3)

umershoukat91
Shopify Partner
8 1 1

Hi,

Was just checking your post, I can not see any problem with the approach you have mentioned. Since i can not see your code can't tell very specifically but it seems like you have problem with metafield definition Mutation.

If you can share your code then i would be able to tell you exact problem.

 

MERN STACK
pushdaddy
Shopify Partner
17 0 1

i was using this code to create new theme file but seems its old theme code and we need to migrate to OS2 theme code, but customer who is using OS1 theme code wont have issue if we start pushing OS2 code in all store as shopify is throwing error with above code and deadline is 1st jan 2023 and any idea on how to change below code for OS2 will be great

 

{%- comment -%}Please DO NOT edit this file{%- endcomment -%}
{%- layout none -%}
{%- assign paramKey = \'q\' -%}
{%- assign paramValue = \'\' -%}
{%- capture contentForQuerystring -%}{{ content_for_header }}{%- endcapture -%}
{%- assign pageUrl = contentForQuerystring | split:\'"pageurl":"\' | last | split:\'"\' | first | split:\'.myshopify.com\' | last |
replace:\'\/\',\'/\' |
replace:\'%20\',\' \' |
replace:\'\u0026\',\'&\'
-%}
{%- assign pageQuerystring = pageUrl | split:\'?\' | last -%}
{%- assign parts = pageQuerystring | split:\'&\' -%}
{%- for part in parts -%}
{%- assign keyAndValue = part | split:\'=\' -%}
{%- if keyAndValue[0] == paramKey -%}
{%- assign paramValue = keyAndValue[1] | strip -%}
{%- endif -%}
{%- endfor -%}
{%- assign namespace = \'pdsocialproof_\' | append: paramValue -%}
{
"metafields": {
"shop": {{ shop.permanent_domain | json }},
"settings": {{ shop.metafields[namespace].settings | json }},
"moneyFormat": {{ shop.money_format | json }}
}
}

mira1224
Shopify Partner
2 0 0

were you able to find a solution to your issue? i'm having the same error