Skip to main content

json_encode

Converts a variable to its JSON representation. This is useful when you need to output structured data as a JSON string.

Usage

{{json_encode variable formatted=1}}

Arguments

variable
The variable to encode as JSON. This can be an object, array, or any other value.

formatted
Whether to format the output with indentation for readability. Set to 0 for compact output, or 1 (default) for pretty-printed output.

Examples

Output the email recipients as JSON (formatted)

{{json_encode email.to}}
[
{
"address": "[email protected]",
"display": "Joe Smith"
},
{
"address": "[email protected]",
"display": "Sarah Jones"
}
]

Output as compact JSON (no formatting)

{{json_encode email.to formatted=0}}
[{"address":"[email protected]","display":"Joe Smith"},{"address":"[email protected]","display":"Sarah Jones"}]

Output a custom object from a previous action

{{json_encode custom.apiResponse}}