> For the complete documentation index, see [llms.txt](https://docs.datajet-app.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.datajet-app.com/liquid/filters/string.md).

# 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.

```liquid
{% assign sku = row.sku | string %}
```

## Syntax

```liquid
{{ value | string }}
```

| Parameter | Description                      |
| --------- | -------------------------------- |
| `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:**

```liquid
{% json %}
{ "externalId": {{ order.id | string | json }} }
{% endjson %}
```

Output:

```json
{ "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:**

```liquid
{% assign index = products | index_by: "id" %}
{% assign key = row.product_id | string %}
{% assign product = index[key] %}
```

**Concatenate without surprises:**

```liquid
{% assign label = "Order #" | append: order.number | string %}
```

## Notes

* Numbers, booleans and strings convert with standard string conversion: `12.5 | string` is `"12.5"`, `true | string` is `"true"`
* `nil` and undefined become `""`, so the result is always a string
* Arrays and objects are JSON-serialized rather than becoming `"[object Object]"`: `items | string` is `"[1,2]"`
* Different from `json`: `json` serializes for transport and **quotes** strings (`"123" | json` is `"\"123\""`), while `string` produces the bare string value
* Casting 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`
