Skip to content

Basic Jinja Variable References

When referencing variables, it is important to configure valid JSON. The examples below walk through the use of two variables defined as a string and a dictionary. Note how the static JSON files and the compiled versions can each create problems in the code.

Example variables

{
    "example_string": "this is a string value",
    "example_dictionary": {
       "username": "my_user",
       "password": "qwerty"
    }
}

Scenario 1: both static and compiled files are valid JSON

This case can be used in any JSON files in a recipe.

Static file (valid)
{
  "data_key": "{{example_string}}"
}
Compiled file (valid)
{
  "data_key": "this is a string value"
}

Scenario 2: static file is not valid JSON, compiled file is valid JSON

This case can be used by all JSON files in the recipe, except for variations.json and variables.json.

Static file (invalid)
{
  "data_key": {{example_dictionary}}
}
Compiled file (valid)
{
  "data_key": {
       "username": "my_user",
       "password": "qwerty",
  }
}

Note

Special cases: Invalid JSON in the static versions of variations.json and variables.json will generate an error when you attempt to run any variation in a recipe. The order will not start, and an error message will display in the Run Variation confirmation dialog.

Scenario 3: static file is valid JSON, compiled file is not valid JSON

This case generates an error at the start of a run (variations.json and variables.json) or at the execution of the affected node (other files).

Static file (valid)
{
  "data_key": "{{example_dictionary}}"
}
Compiled file (invalid)
{
  "data_key": "{"username": "my_user", "password": "qwerty"}"
}

Scenario 4: static file is not valid JSON, compiled file is not valid JSON

This case generates an error at the start of a run (variations.json and variables.json) or at the execution of the affected node (other files).

Static file (invalid)
{
  "data_key": {{example_string}}
}
Compiled file (invalid)
{
  "data_key": this is a string value
}