kestra-io/kestra · error · PebbleException

Unable to transform to json value '{input}' with type '{inpu

Error message

Unable to transform to json value '{input}' with type '{input.getClass().getName()}'

What it means

The 'toJson' filter serializes its input to a JSON string with the default Jackson ObjectMapper. When writeValueAsString() throws JsonProcessingException (cyclic graph, missing serializer, Jackson configuration error), the filter rethrows it as a PebbleException that includes the value and its Java type.

Source

Thrown at core/src/main/java/io/kestra/core/runners/pebble/filters/ToJsonFilter.java:33

public class ToJsonFilter implements Filter {
    private static final ObjectMapper MAPPER = JacksonMapper.ofJson();

    @Override
    public List<String> getArgumentNames() {
        return null;
    }

    @Override
    public Object apply(Object input, Map<String, Object> args, PebbleTemplate self, EvaluationContext context, int lineNumber) throws PebbleException {
        if (input == null) {
            return "null";
        }

        try {
            return MAPPER.writeValueAsString(input);
        } catch (JsonProcessingException e) {
            throw new PebbleException(e, "Unable to transform to json value '" + input + "' with type '" + input.getClass().getName() + "'", lineNumber, self.getName());
        }
    }
}

View on GitHub (pinned to 823fada927)

Solutions

  1. Project the needed fields into a plain map before filtering.
  2. Ensure custom types used in outputs register an appropriate Jackson module.
  3. Avoid cyclic references by removing parent pointers before serialization.

Example fix

// before
{{ execution | toJson }}
// after
{{ {id: execution.id, namespace: flow.namespace} | toJson }}
Defensive patterns

Strategy: type-guard

Validate before calling

{{ {id: execution.id, namespace: flow.namespace} | toJson }}

Type guard

// Java: restrict to Jackson-serializable shapes
if (value instanceof Iterable || value instanceof Map || value.isPrimitive()
        || value instanceof String || value instanceof Number) { /* safe-ish */ }

Prevention

When it happens

Trigger: Piping a recursive or non-serializable object into {{ x | toJson }}; passing an object whose fields include types Jackson cannot handle (e.g. raw InputStream, custom type without a module).

Common situations: Trying to JSON-encode the whole execution or flow variable (which carries back-references); serializing plugin-specific types not covered by registered Jackson modules.

Related errors


AI-assisted analysis of kestra-io/kestra@823fada927 (2026-08-14). Data as JSON: /api/errors/847c39923c358eae. Report an issue: GitHub.