{"record":{"id":"847c39923c358eae","repo":"kestra-io/kestra","slug":"unable-to-transform-to-json-value-input-with-t","errorCode":null,"errorMessage":"Unable to transform to json value '{input}' with type '{input.getClass().getName()}'","messagePattern":"Unable to transform to json value '(.+?)' with type '(.+?)'","errorType":"exception","errorClass":"PebbleException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/io/kestra/core/runners/pebble/filters/ToJsonFilter.java","lineNumber":33,"sourceCode":"\npublic class ToJsonFilter implements Filter {\n    private static final ObjectMapper MAPPER = JacksonMapper.ofJson();\n\n    @Override\n    public List<String> getArgumentNames() {\n        return null;\n    }\n\n    @Override\n    public Object apply(Object input, Map<String, Object> args, PebbleTemplate self, EvaluationContext context, int lineNumber) throws PebbleException {\n        if (input == null) {\n            return \"null\";\n        }\n\n        try {\n            return MAPPER.writeValueAsString(input);\n        } catch (JsonProcessingException e) {\n            throw new PebbleException(e, \"Unable to transform to json value '\" + input + \"' with type '\" + input.getClass().getName() + \"'\", lineNumber, self.getName());\n        }\n    }\n}\n","sourceCodeStart":15,"sourceCodeEnd":37,"githubUrl":"https://github.com/kestra-io/kestra/blob/823fada9274c4f9c251ea0a516460a4f7d958032/core/src/main/java/io/kestra/core/runners/pebble/filters/ToJsonFilter.java#L15-L37","documentation":"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.","triggerScenarios":"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).","commonSituations":"Trying to JSON-encode the whole execution or flow variable (which carries back-references); serializing plugin-specific types not covered by registered Jackson modules.","solutions":["Project the needed fields into a plain map before filtering.","Ensure custom types used in outputs register an appropriate Jackson module.","Avoid cyclic references by removing parent pointers before serialization."],"exampleFix":"// before\n{{ execution | toJson }}\n// after\n{{ {id: execution.id, namespace: flow.namespace} | toJson }}","handlingStrategy":"type-guard","validationCode":"{{ {id: execution.id, namespace: flow.namespace} | toJson }}","typeGuard":"// Java: restrict to Jackson-serializable shapes\nif (value instanceof Iterable || value instanceof Map || value.isPrimitive()\n        || value instanceof String || value instanceof Number) { /* safe-ish */ }","tryCatchPattern":null,"preventionTips":["Project large/recursive objects to a plain map before toJson.","Keep plugin outputs composed of standard types (Map, List, primitives).","Register Jackson modules for any custom types in outputs."],"tags":["pebble","filter","serialization","json","jackson"],"backgroundTag":null,"analyzedSha":"823fada9274c4f9c251ea0a516460a4f7d958032","analyzedAt":"2026-08-14T06:15:17.947Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}