{"record":{"id":"7cc729460576113c","repo":"kestra-io/kestra","slug":"the-fromjson-function-expects-an-argument-json","errorCode":null,"errorMessage":"The 'fromJson' function expects an argument 'json'.","messagePattern":"The 'fromJson' function expects an argument 'json'\\.","errorType":"validation","errorClass":"PebbleException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/io/kestra/core/runners/pebble/functions/FromJsonFunction.java","lineNumber":31,"sourceCode":"import io.pebbletemplates.pebble.template.PebbleTemplate;\n\npublic class FromJsonFunction implements KestraFunction {\n    public static final String NAME = \"fromJson\";\n    private static final ObjectMapper MAPPER = JacksonMapper.ofJson();\n\n    public List<String> getArgumentNames() {\n        return List.of(\"json\");\n    }\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        }","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/kestra-io/kestra/blob/823fada9274c4f9c251ea0a516460a4f7d958032/core/src/main/java/io/kestra/core/runners/pebble/functions/FromJsonFunction.java#L13-L49","documentation":"Thrown by the 'fromJson' function when the args map does not contain the 'json' entry. 'json' is the single required argument (declared via getArgumentNames). A later branch returns null if json is present-but-null, and another checks the type, so this guard specifically covers a missing key.","triggerScenarios":"Calling fromJson() with no arguments, fromJson(other='x'), or misspelling the argument so Pebble does not bind it under 'json'.","commonSituations":"Forgetting the argument; assuming fromJson() takes a file path directly (it takes JSON content, typically via readFile()); copy-paste errors.","solutions":["Provide the 'json' argument, usually the output of readFile() on a JSON file: fromJson(readFile(outputs.fetch.body)).","If using named arguments, spell it exactly as 'json'.","Ensure the expression resolves to a JSON string, not a path or a parsed object."],"exampleFix":"# before\nobj: \"{{ fromJson() }}\"\n# after\nobj: \"{{ fromJson(readFile('json/namespace/file')) }}\"","handlingStrategy":"validation","validationCode":"# Ensure the 'json' argument is provided before calling fromJson().\n# {{ (jsonContent != null) ? fromJson(jsonContent) : null }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass the 'json' argument, typically via readFile() of a JSON file.","Spell the argument exactly as 'json'.","Confirm the expression resolves to JSON text, not a path or object.","Remove getArgumentDefaults() placeholders before production."],"tags":["pebble","fromjson","serialization","json","validation","missing-argument"],"backgroundTag":null,"analyzedSha":"823fada9274c4f9c251ea0a516460a4f7d958032","analyzedAt":"2026-08-14T06:15:17.947Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}