json
Captures content and parses it as JSON, allowing immediate access to properties. Works like capture but automatically converts the content to a JSON object.
{% json my_data %}
{
"name": "Example",
"value": 123
}
{% endjson %}
{% log my_data.name %}Syntax
{% json variable_name %}
{ JSON content }
{% endjson %}Parameters
variable_name
Yes
Name of the variable to store the parsed JSON
How It Works
Content between
{% json %}and{% endjson %}is rendered (Liquid variables are interpolated)The resulting string is parsed as JSON
The parsed object is assigned to the specified variable
Properties can be accessed immediately using dot notation
Examples
Basic JSON object:
Dynamic JSON with Liquid variables:
Build request body for HTTP call:
Create array of objects:
Nested JSON structure:
Build GraphQL variables:
Set function return value:
Conditional JSON content:
Error Handling
If the content is not valid JSON, an error is thrown with the invalid content and parse error message:
Error message will include the problematic JSON and the specific parse error.
Notes
Content is first rendered as Liquid, then parsed as JSON
Use
| jsonfilter to safely embed arrays or objects:{{ my_array | json }}Strings in JSON must be properly quoted with double quotes
Special characters in string values should be escaped
Variable names
responseandreturnhave special meaning in functionsInvalid JSON will throw an error - validate your JSON structure
Use trailing comma handling with
{% unless forloop.last %},{% endunless %}in loops
Last updated