LoginSignup
1
1

More than 1 year has passed since last update.

【Shopify Liquid】メタフィールドに登録したJSONを取得する

Posted at

ShopifyのメタフィールドにJSON形式で登録したデータをLiquidで取得する方法を記載します。

以下のようなJSONをjsonというネームフィールドで登録しているとします。

{
  "name": "taro",
  "age": "30",
  "country": "japan"
}

nameフィールドを取得したい場合は以下のように記述します。

{{ blog.metafields.custom.json.value.name }}

すべてのフィールドを取得したい場合はforを使います。

{%- for metafield in blog.metafields.custom.json.value -%}
  {{ metafield.name }}
  {{ metafield.age}}
  {{ metafield.country}}
{%- endfor -%}

当初、以下のように記述していましたがこれでは値を取得できませんでした。

// NG
{{ blog.metafields.custom.json.name }}
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1