Edit on GitHub
Jump to docs navigation

Twig Components / Methods / json_encode

json_encode(options, depth) is a Twig filter to Treturn the JSON representation of a value:

{{ data|json_encode() }}


Internally, Twig uses the PHP json_encode function.


  • options: A bitmask of json_encode options: {{ data|json_encode(constant('JSON_PRETTY_PRINT')) }} . Combine constants using bitwise operators: {{ data|json_encode(constant('JSON_PRETTY_PRINT') b-or constant('JSON_HEX_QUOT')) }}

Source: Twig

Edit this page on GitHub
Couldn't find what you were looking for? We are happy to help you in the forum, on Slack or on Github.