Twig Components / Methods / json_encode
Note: You are currently reading the documentation for Bolt 5.0. Looking for the documentation for Bolt 5.2 instead?
json_encode(options, depth)
is a Twig filter to return the JSON representation of a value:
{{ data|json_encode() }}
Internally, Twig uses the PHP [json_encode](https://www.php.net/json_encode) function. ## Arguments - options: A bitmask of [json_encode options](https://www.php.net/manual/en/json.constants.php): `{{ data|json_encode(constant('JSON_PRETTY_PRINT')) }}` . Combine constants using [bitwise operators](https://twig.symfony.com/doc/3.x/templates.html#template_logic): `{{ data|json_encode(constant('JSON_PRETTY_PRINT') b-or constant('JSON_HEX_QUOT')) }}` Source: [Twig](https://twig.symfony.com/json_encode)
Couldn't find what you were looking for? We are happy to help you in the forum, on Slack or on Github.