Liquid Snippets by ALSEL
📘 公式リファレンス🔧 リファレンス/フィルター初級

json フィルター(データを JSON 文字列に変換)

文字列またはオブジェクトを JSON 形式の文字列に変換するフィルター。JavaScript で直接使用する際は、フィルターが自動的にクォートを付与してエスケープするため、追加で引用符を加える必要がない。

用途
商品データやカート情報を JavaScript に渡すときや、API レスポンスとして構造化データを JSON 形式で出力するとき。
設置場所
Liquid テンプレート内で `{{ product | json }}` や `{{ collection | json }}` の形で使い、JSON 文字列を生成する。結果を `<script>` タグ内に埋め込むか、data 属性に割り当てて JavaScript で参照できるようにする。
注意点
2017 年 12 月 5 日以降に作成された Shopify ストアで product オブジェクトに json フィルターを適用した場合、バリアントの `inventory_quantity` と `inventory_policy` プロパティは出力されない。これはボットやクローラーによる在庫情報の無断取得を防ぐための仕様。在庫情報が必要なときは、個別のバリアントオブジェクトから直接取得する。
タグ:jsonformatdata-structurejavascriptapi

仕様

30 行 / json
{
  "category": "format",
  "deprecated": false,
  "deprecation_reason": "",
  "description": "&gt; Tip:\n&gt; When using the JSON output in JavaScript, you don't need to wrap it in quotes because the `json` filter includes them.\n&gt; The `json` filter also escapes any quotes inside the output.\n\n#### Product inventory\n\nWhen applied to a [`product` object](/docs/api/liquid/objects/product) on any Shopify store created after December 5, 2017, the\n`json` filter doesn't output values for the `inventory_quantity` and `inventory_policy` properties of any associated\n[variants](/docs/api/liquid/objects/variant). These properties are excluded to help prevent bots and crawlers from retrieving\ninventory quantities for stores to which they aren't granted access.\n\nIf you need inventory information, you can access it through individual variants.",
  "parameters": [],
  "return_type": [
    {
      "type": "string",
      "name": "",
      "description": "",
      "array_value": ""
    }
  ],
  "examples": [
    {
      "name": "",
      "description": "",
      "syntax": "",
      "path": "/products/crocodile-tears",
      "raw_liquid": "{{ product | json }}",
      "parameter": false,
      "display_type": "text",
      "show_data_tab": true
    }
  ],
  "summary": "Converts a string, or object, into JSON format.",
  "syntax": "variable | json",
  "name": "json"
}

出典・ライセンス

License:
MIT

このコードは Shopify 著作の MIT ライセンスソースです。 原本の著作権は Shopify が保有します。日本語訳は ALSEL によるものです。

関連項目

📘 公式リファレンス🔧 リファレンス/フィルター初級

avatar フィルター(顧客アバター画像HTML生成)

顧客アバターが存在する場合、それを表示する HTML タグを生成するフィルター。customer オブジェクトに対して使用する。

📁 theme-liquid-docs·MIT·19
📘 公式リファレンス🔧 リファレンス/フィルター初級

default_errors フィルター(フォーム送信エラーを日本語化)

form.errors の各エラーコードに対応する既定のエラーメッセージを自動生成するフィルター。フォーム送信時の入力値不正や必須項目空白などのエラーを言語別に出力する。

📁 theme-liquid-docs·MIT·19
📘 公式リファレンス🔧 リファレンス/フィルター初級

date フィルター(日付を指定形式でフォーマット)

日付値を指定されたフォーマット文字列に従って整形する。フォーマット文字列が空の場合は元の値がそのまま返される。入力が日付に変換できない場合も元の値が返される。

📁 theme-liquid-docs·MIT·19
📘 公式リファレンス🔧 リファレンス/フィルター初級

payment_terms フィルター(Shop Pay分割払いバナーを生成)

product フォームまたは cart フォームに対して使用し、Shop Pay の分割払いオプションを表示するための HTML を生成するフィルター。顧客が購入時に分割払いプランを選択できるようにする。

📁 theme-liquid-docs·MIT·19
📘 公式リファレンス🔧 リファレンス/フィルター初級

abs フィルター(数値の絶対値を取得)

負の数を正の数に変換する。数値の絶対値(ゼロからの距離)を返すフィルター。

📁 theme-liquid-docs·MIT·30
📘 公式リファレンス🔧 リファレンス/フィルター初級

append フィルター(文字列の末尾に追加)

文字列の末尾に別の文字列を連結するフィルター。URL パスの結合やテキストの接尾辞追加に使う。

📁 theme-liquid-docs·MIT·30