> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kiwify.com.br/llms.txt
> Use this file to discover all available pages before exploring further.

# Misc filters

> Miscellaneous filters for various operations in Liquid templates.

## `default`

Allows you to specify a fallback in case a value doesn't exist. `default` will show its value if the left side is falsy or empty (`string` or `Array`).

In this example, `product_price` is not defined, so the default value is used.

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    {{ product_price | default: 2.99 }}
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    2.99
    ```
  </CodeGroup>
</Columns>

In this example, `product_price` is defined, so the default value is not used.

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    {% assign product_price = 4.99 %}
    {{ product_price | default: 2.99 }}
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    4.99
    ```
  </CodeGroup>
</Columns>

In this example, `product_price` is empty, so the default value is used.

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    {% assign product_price = "" %}
    {{ product_price | default: 2.99 }}
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    2.99
    ```
  </CodeGroup>
</Columns>

### Allowing `false`

To allow variables to return `false` instead of the default value, you can use the `allow_false` parameter.

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    {% assign display_price = false %}
    {{ display_price | default: true, allow_false: true }}
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    false
    ```
  </CodeGroup>
</Columns>

## `json`

Convert values to string via `JSON.stringify()`, for debug purpose.

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    {% assign arr = "foo bar coo" | split: " " %}
    {{ arr | json }}
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    ["foo","bar","coo"]
    ```
  </CodeGroup>
</Columns>

## `parse_json`

Convert a string value to a valid JSON object. If the value is not a valid JSON, the returned value will be `nil`.

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    {% assign obj = '{"foo": "bar"}' | parse_json %}
    {% assign arr = '["Hi", "there"]' | parse_json %}
    {% assign invalid = '{"foo" = "bar"}' | parse_json %}
    {{ obj.foo }}
    {{ arr[1]}}
    {{ invalid }}
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    bar
    there

    ```
  </CodeGroup>
</Columns>

### Space

An additional `space` parameter can be specified to format the JSON.

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    {% assign arr = "foo bar coo" | split: " " %}
    {{ arr | json: 4 }}
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    [
        "foo",
        "bar",
        "coo"
    ]
    ```
  </CodeGroup>
</Columns>

## `jsonify`

See json.

## `inspect`

Similar with `json`, but `inspect` allows cyclic structure. For the scope below:

```
const foo = {
    bar: 'BAR'
}
foo.foo = foo
const scope = { foo }
```

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    {% foo | inspect %}
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    {"bar":"BAR","foo":"[Circular]"}
    ```
  </CodeGroup>
</Columns>

### Formatting

An additional `space` argument can be specified for the indent width.

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    {{ foo | inspect: 4 }}
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    {
        "bar": "BAR",
        "foo": "[Circular]"
    }
    ```
  </CodeGroup>
</Columns>

## `to_integer`

Convert values to number.

<Columns cols={2}>
  <CodeGroup>
    ```liquid Code theme={null}
    {{ "123" | to_integer | json }}
    ```
  </CodeGroup>

  <CodeGroup>
    ```liquid Output theme={null}
    123
    ```
  </CodeGroup>
</Columns>
