Format.json ViewHelper <f:format.json>

Wrapper for PHPs json_encode function. See https://www.php.net/manual/function.json-encode.php.

Examples

Encoding a view variable

{someArray -> f:format.json()}
Copied!

["array","values"] Depending on the value of {someArray}.

Associative array

{f:format.json(value: {foo: 'bar', bar: 'baz'})}
Copied!

{"foo":"bar","bar":"baz"}

Non associative array with forced object

{f:format.json(value: {0: 'bar', 1: 'baz'}, forceObject: true)}
Copied!

{"0":"bar","1":"baz"}

Source code

Go to the source code of this ViewHelper: Format\JsonViewHelper.php (GitHub).

Arguments

The following arguments are available for the format.json ViewHelper:

forceObject
Type
bool
Default
false
Outputs an JSON object rather than an array
value
Type
mixed
The incoming data to convert, or null if VH children should be used