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

Parameter
Required
Description

variable_name

Yes

Name of the variable to store the parsed JSON

How It Works

  1. Content between {% json %} and {% endjson %} is rendered (Liquid variables are interpolated)

  2. The resulting string is parsed as JSON

  3. The parsed object is assigned to the specified variable

  4. 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 | json filter 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 response and return have special meaning in functions

  • Invalid JSON will throw an error - validate your JSON structure

  • Use trailing comma handling with {% unless forloop.last %},{% endunless %} in loops

Last updated