Liquid Template Playground
Test and debug Liquid template expressions with live evaluation. Transform webhook payloads using Shopify's Liquid template language.
How Liquid templates work
A Liquid template is text with two kinds of tags. Output tags, {{ ... }}, print a value, optionally passed through filters such as upcase or join. Logic tags, {% ... %}, control what gets printed: if, unless, for, assign, and capture. Everything outside the tags is copied to the output unchanged.
The examples below render against this Shopify-style order:
{
"id": 5512345678,
"email": "jon@example.com",
"note": "Leave at the \"side\" door",
"total_price": "248.00",
"customer": { "first_name": "Jon" },
"line_items": [
{ "title": "Trail Runner", "sku": "TR-42", "quantity": 2, "price": "99.00" },
{ "title": "Wool Socks", "sku": "WS-01", "quantity": 2, "price": "25.00" }
]
}Liquid syntax at a glance
| Syntax | What it does |
|---|---|
{{ customer.first_name }} | Print a value. Use dots for nested fields. |
{{ line_items[0].title }} | Index into an array. |
{{ email | upcase }} | Apply a filter. Chain filters left to right. |
{% if x > 1 %}…{% endif %} | Conditional block, with elsif and else. |
{% for item in line_items %}…{% endfor %} | Loop. forloop.first, forloop.last and forloop.index are available inside. |
{% assign total = total_price | plus: 0 %} | Store a value in a variable. |
{%- … -%} | Dashes trim the whitespace and newlines around a tag. |
Worked examples
Print a nested field through a filter
{{ customer.first_name | upcase }}→ "JON"List line items
{% for item in line_items %}{{ item.quantity }} x {{ item.title }}{% unless forloop.last %}, {% endunless %}{% endfor %}→ "2 x Trail Runner, 2 x Wool Socks"Join one field from every item
{{ line_items | map: "sku" | join: "," }}→ "TR-42,WS-01"Add up quantities
{{ line_items | sum: "quantity" }}→ "4"Branch on the order value
{% assign total = total_price | plus: 0 %}{% if total > 200 %}high-value{% else %}standard{% endif %}→ "high-value"Fill in a missing field
{{ coupon | default: "none" }}→ "none"Build a JSON body with a loop
{
"order": {{ id }},
"items": [
{%- for item in line_items %}
{ "sku": {{ item.sku | json }}, "qty": {{ item.quantity }} }{% unless forloop.last %},{% endunless %}
{%- endfor %}
]
}→ {
"order": 5512345678,
"items": [
{ "sku": "TR-42", "qty": 2 },
{ "sku": "WS-01", "qty": 2 }
]
}Liquid gotchas when generating JSON
- Quotes inside values break the JSON.
"note": "{{ note }}"renders"note": "Leave at the "side" door", which does not parse. Write"note": {{ note | json }}instead. - Trailing commas. Wrap the separator in
{% unless forloop.last %},{% endunless %}so the last item has none. - Numbers that arrive as strings. Shopify sends prices as
"248.00".| plus: 0converts a string to a number before you compare or do arithmetic. - Unknown filters fail. Hookbase runs Liquid with strict filters, so a misspelled filter is an error rather than a silently empty value.
Liquid or JSONata?
Liquid is the better fit when the output is text: a Slack or email message, an XML body, or a JSON document you want to lay out by hand. JSONata is better when you are reshaping JSON into JSON, filtering arrays, or computing values, because it works on data instead of text and cannot produce invalid JSON. Try the same payload in the JSONata playground to compare.
Use Liquid templates on live webhooks
Hookbase can apply a Liquid template to every webhook a route receives, then deliver the result to your destination. In a route, the event body is under payload and request headers are under headers. See payload transforms or the transforms guide.
Frequently asked questions
What is a Liquid template?+
Liquid is a template language created by Shopify. A template is plain text with {{ output }} tags that insert values and {% tag %} blocks for logic such as if, for, and assign. It is used for Shopify themes and emails, and for turning webhook JSON into a message or a new JSON body.
Is this Liquid playground free?+
Yes. It runs in your browser with the liquidjs library, needs no account, and your JSON never leaves the page. Paste a payload, edit the template, and the output updates as you type.
Why does divided_by give a different answer than Shopify?+
This playground and Hookbase use liquidjs, where 4999 | divided_by: 100 returns 49.99. Shopify's own Liquid does integer division when both numbers are integers and returns 49. Test with the engine you will deploy to.
How do I output valid JSON from Liquid?+
Pass strings through the json filter instead of wrapping them in quotes yourself. {{ note | json }} adds the quotes and escapes any quotes or newlines inside the value, so the result always parses.
Can I use Liquid to transform webhooks?+
Yes. Hookbase runs Liquid transforms on incoming webhooks before delivering them. In a Hookbase route the event body is available as payload (with data as an alias) and request headers as headers, so {{ email }} in this playground becomes {{ payload.email }} in a route.
Want more? Try webhook payload transformation in Hookbase
Get started free with no credit card required.