kestra-io/kestra · error · PebbleException
The 'fromJson' function expects an argument 'json'.
Error message
The 'fromJson' function expects an argument 'json'.
What it means
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.
Source
Thrown at core/src/main/java/io/kestra/core/runners/pebble/functions/FromJsonFunction.java:31
import io.pebbletemplates.pebble.template.PebbleTemplate;
public class FromJsonFunction implements KestraFunction {
public static final String NAME = "fromJson";
private static final ObjectMapper MAPPER = JacksonMapper.ofJson();
public List<String> getArgumentNames() {
return List.of("json");
}
@Override
public Map<String, String> getArgumentDefaults() {
return Map.of("json", ReadFileFunction.NAME + "('json/namespace/file')");
}
@Override
public Object execute(Map<String, Object> args, PebbleTemplate self, EvaluationContext context, int lineNumber) {
if (!args.containsKey("json")) {
throw new PebbleException(null, "The 'fromJson' function expects an argument 'json'.", lineNumber, self.getName());
}
if (args.get("json") == null) {
return null;
}
if (!(args.get("json") instanceof String)) {
throw new PebbleException(null, "The 'fromJson' function expects an argument 'json' with type string.", lineNumber, self.getName());
}
String json = (String) args.get("json");
;
try {
return MAPPER.readValue(json, JacksonMapper.OBJECT_TYPE_REFERENCE);
} catch (JsonProcessingException e) {
throw new PebbleException(null, "Invalid json: " + e.getMessage(), lineNumber, self.getName());
}View on GitHub (pinned to 823fada927)
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.
Example fix
# before
obj: "{{ fromJson() }}"
# after
obj: "{{ fromJson(readFile('json/namespace/file')) }}" Defensive patterns
Strategy: validation
Validate before calling
# Ensure the 'json' argument is provided before calling fromJson().
# {{ (jsonContent != null) ? fromJson(jsonContent) : null }} Prevention
- 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.
When it happens
Trigger: Calling fromJson() with no arguments, fromJson(other='x'), or misspelling the argument so Pebble does not bind it under 'json'.
Common situations: Forgetting the argument; assuming fromJson() takes a file path directly (it takes JSON content, typically via readFile()); copy-paste errors.
Related errors
- The 'fromJson' function expects an argument 'json' with type
- Invalid json: {e.getMessage()}
- The 'fromIon' function expects an argument 'ion'.
- Unable to transform to json value '{input}' with type '{inpu
- The 'encrypt' function expects two arguments 'key' and 'plai
AI-assisted analysis of kestra-io/kestra@823fada927 (2026-08-14).
Data as JSON: /api/errors/7cc729460576113c.
Report an issue: GitHub.