string
Casts a value to a string. Use it when a number must stay a string — IDs, SKUs, postal codes, anything with leading zeros — especially inside a {% json %} block.
{% assign sku = row.sku | string %}Syntax
{{ value | string }}value
Any value to convert to a string
Return Value
Returns a string. nil becomes ""; arrays and objects are JSON-serialized.
Examples
Keep an ID a string in a JSON payload:
{% json %}
{ "externalId": {{ order.id | string | json }} }
{% endjson %}Output:
{ "externalId": "5123456789" }This replaces the "{{ order.id }}" hand-quoting workaround, which breaks as soon as the value contains a quote or is nil.
Build a lookup key from a numeric column:
Concatenate without surprises:
Notes
Numbers, booleans and strings convert with standard string conversion:
12.5 | stringis"12.5",true | stringis"true"niland undefined become"", so the result is always a stringArrays and objects are JSON-serialized rather than becoming
"[object Object]":items | stringis"[1,2]"Different from
json:jsonserializes for transport and quotes strings ("123" | jsonis"\"123\""), whilestringproduces the bare string valueCasting a number to a string does not restore lost leading zeros — cast at the point the value arrives, before any arithmetic
See also:
json,integer,type
Last updated