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

# json_encode

### Introduction

The `json_encode` filter converts a variable—such as an array or object—into a JSON-formatted string. This filter is especially useful when you need to pass data from a Twig template to a JavaScript script or an API that consumes JSON.

### Example of Use

Example of how to use the `json_encode` filter to convert an array into a JSON string:

```twig theme={null}
{% set order = {number: 12345, customer: 'John Smith', items: ['Product 1', 'Product 2', 'Product 3'], total_value: 299.99} %}

{{ order|json_encode }}
```

### Output Example of the Code

<img src="https://mintcdn.com/reportana/Jha6odPLZMMTun1e/jsonencode_en.png?fit=max&auto=format&n=Jha6odPLZMMTun1e&q=85&s=cc053119f014d2ce7e7838c431a35ae9" alt="Result of `json_encode` Filter" width="1270" height="211" data-path="jsonencode_en.png" />
