{"record":{"id":"a57a7fd806812ef1","repo":"kestra-io/kestra","slug":"the-fromjson-function-expects-an-argument-json-a57a7f","errorCode":null,"errorMessage":"The 'fromJson' function expects an argument 'json' with type string.","messagePattern":"The 'fromJson' function expects an argument 'json' with type string\\.","errorType":"validation","errorClass":"PebbleException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/io/kestra/core/runners/pebble/functions/FromJsonFunction.java","lineNumber":39,"sourceCode":"    }\n\n    @Override\n    public Map<String, String> getArgumentDefaults() {\n        return Map.of(\"json\", ReadFileFunction.NAME + \"('json/namespace/file')\");\n    }\n\n    @Override\n    public Object execute(Map<String, Object> args, PebbleTemplate self, EvaluationContext context, int lineNumber) {\n        if (!args.containsKey(\"json\")) {\n            throw new PebbleException(null, \"The 'fromJson' function expects an argument 'json'.\", lineNumber, self.getName());\n        }\n\n        if (args.get(\"json\") == null) {\n            return null;\n        }\n\n        if (!(args.get(\"json\") instanceof String)) {\n            throw new PebbleException(null, \"The 'fromJson' function expects an argument 'json' with type string.\", lineNumber, self.getName());\n        }\n\n        String json = (String) args.get(\"json\");\n        ;\n\n        try {\n            return MAPPER.readValue(json, JacksonMapper.OBJECT_TYPE_REFERENCE);\n        } catch (JsonProcessingException e) {\n            throw new PebbleException(null, \"Invalid json: \" + e.getMessage(), lineNumber, self.getName());\n        }\n    }\n}\n","sourceCodeStart":21,"sourceCodeEnd":52,"githubUrl":"https://github.com/kestra-io/kestra/blob/823fada9274c4f9c251ea0a516460a4f7d958032/core/src/main/java/io/kestra/core/runners/pebble/functions/FromJsonFunction.java#L21-L52","documentation":"Thrown by 'fromJson' when the 'json' argument is present, non-null, but not a String. The function only parses String input with Jackson; a number, boolean, map, or list is rejected because it is already a structured value and not JSON text.","triggerScenarios":"Passing fromJson() a numeric literal, a list/map that is already deserialized, or a boolean; chaining a function that returns a structured object instead of text.","commonSituations":"Double-parsing (e.g. fromJson(fromJson(...))) or passing the output of a task that already returns a parsed object; binding an input of type number/array to the json argument.","solutions":["Pass a JSON string, typically via readFile() of a .json file or a task output that is text.","If the value is already a structured object, use it directly instead of fromJson().","Verify the upstream expression returns a string before calling fromJson()."],"exampleFix":"# before - passing a number literal\nobj: \"{{ fromJson(42) }}\"\n# after - pass JSON text\nobj: \"{{ fromJson(readFile('config.json')) }}\"","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"# Pebble-side guard: fromJson only accepts a string.\n# {{ (content is string) ? fromJson(content) : content }}","tryCatchPattern":null,"preventionTips":["Pass a JSON string to fromJson(), typically via readFile().","Do not pass already-parsed objects/lists/numbers.","Verify the upstream expression returns a string.","Avoid double-parsing with fromJson(fromJson(...))."],"tags":["pebble","fromjson","serialization","json","type-validation","validation"],"backgroundTag":null,"analyzedSha":"823fada9274c4f9c251ea0a516460a4f7d958032","analyzedAt":"2026-08-14T06:15:17.947Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}