Skip to content

Json ​

Converts a value to JSON. Strings, arrays and objects print as JSON. Numbers, booleans and nil print as JSON values, without quotes.

Example ​

Data
json
{
  "product": {
    "title": "Hat",
    "price": 10,
    "available": true,
    "sku": null
  }
}
liquid
<script>
  const product = {{ product | json }};
  const price = {{ product.price | json }};
  const available = {{ product.available | json }};
  const sku = {{ product.sku | json }};
</script>

Output

html
<script>
  const product = {"title":"Hat","price":10,"available":true,"sku":null};
  const price = 10;
  const available = true;
  const sku = null;
</script>