You are viewing the docs for v1.3, which is not the latest release.
View latest

Adapt Flows to the NON_NULL JSON Serialization Strategy

For the complete documentation index, see llms.txt. For a full content snapshot, see llms-full.txt. Append .md to any kestra.io/docs/* URL for plain Markdown.

JSON Object Serialization

How to adapt flows to the NON_NULL JSON serialization strategy.

Kestra 0.17 migrates away from the previously used NON_DEFAULT JSON serialization strategy to fix various limitations and make the flow behavior more user-friendly. This change makes empty lists or maps serialized instead of being undefined. Adapting Pebble expressions relying on the previously existing behavior is necessary to keep the functionality untouched.

There are three main cases where Pebble expressions might be affected:

  1. Operators, Tags, and Tests
  2. Pebble Syntax
  3. Conditions in Pebble

0.16

yamlid: inputsV16
namespace: company.team

inputs:
  - id: optionalInput
    type: STRING
    required: false

tasks:
  - id: testNullCoalescing
    type: io.kestra.core.tasks.log.Log
    message: "=>{{ inputs.optionalInput ?? 'undefined' }}<=" # =>undefined<=
  - id: testOutputsMapPrepare
    type: io.kestra.plugin.scripts.python.Script
    script: "print('test')"
  - id: testOutputsMap
    type: io.kestra.core.tasks.log.Log
    message: "=>{{ outputs.testOutputsMapPrepare.outputFiles ?? 'empty' }}<=" # =>empty<=
  - id: testCondition
    type: io.kestra.core.tasks.flows.If
    condition: "{{ outputs.testOutputsMapPrepare.outputFiles is defined }}"
    then:
      - id: logOutputFiles
        type: io.kestra.core.tasks.log.Log
        message: "found"
    else:
      - id: logNoOutputFiles
        type: io.kestra.core.tasks.log.Log
        message: "not found" # not found

0.17

yamlid: inputsV17
namespace: company.team

inputs:
  - id: optionalInput
    type: STRING
    required: false

tasks:
  - id: testNullCoalescing
    type: io.kestra.plugin.core.log.Log
    message: "=>{{ inputs.optionalInput ?? 'undefined' }}<=" # =><=
  - id: testOutputsMapPrepare
    type: io.kestra.plugin.scripts.python.Script
    taskRunner:
      type: io.kestra.plugin.scripts.runner.docker.Docker
    containerImage: python:3.11-slim
    script: "print('test')"
  - id: testOutputsMap
    type: io.kestra.plugin.core.log.Log
    message: "=>{{ outputs.testOutputsMapPrepare.outputFiles ?? 'empty' }}<=" # =>{}<=
  - id: testCondition
    type: io.kestra.core.tasks.flows.If
    condition: "{{ outputs.testOutputsMapPrepare.outputFiles is defined }}"
    then:
      - id: logOutputFiles
        type: io.kestra.plugin.core.log.Log
        message: "found" # found
    else:
      - id: logNoOutputFiles
        type: io.kestra.plugin.core.log.Log
        message: "not found"

For more information, you can refer the Improved serialization of JSON objects page.