kestra-io/kestra · error · PebbleException
Invalid json: {e.getMessage()}
Error message
Invalid json: {e.getMessage()} What it means
Thrown by 'fromJson' when Jackson's MAPPER.readValue raises a JsonProcessingException. The input was a string but not valid JSON, so parsing aborted; the message appends the Jackson parser's explanation (e.g. unexpected token, EOF).
Source
Thrown at core/src/main/java/io/kestra/core/runners/pebble/functions/FromJsonFunction.java:48
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
- Validate the string is well-formed JSON (use jq or a linter) before passing it.
- If the source is YAML or another format, convert it to JSON first or use the appropriate parser.
- Handle API error responses (e.g. check status/content-type) before parsing the body as JSON.
- For user-supplied JSON inputs, enable a JSON validation rule at the input boundary.
Example fix
# before - YAML-ish content passed to fromJson()
obj: "{{ fromJson(readFile('config.yaml')) }}"
# after - ensure valid JSON content
obj: "{{ fromJson(readFile('config.json')) }}" Defensive patterns
Strategy: validation
Validate before calling
# Light pre-check before fromJson(): must look like a JSON object or array.
# {{ (jsonContent trim starts with '{' or jsonContent trim starts with '[') ? fromJson(jsonContent) : null }} Try / catch
# Pebble has no try/catch. In a wrapper task, catch JsonProcessingException and return a fallback or log the raw input.
Prevention
- Validate the string is well-formed JSON (jq/linter) before parsing.
- Check API status/content-type before parsing a response body.
- Convert non-JSON formats upstream; do not feed YAML/INI to fromJson().
- Add JSON validation at input boundaries for user-supplied payloads.
When it happens
Trigger: Passing fromJson() a malformed JSON string (trailing comma, unquoted keys, single quotes, truncated), a JSON5/YAML/INI string, or HTML/plain text mistaken for JSON.
Common situations: Reading a non-JSON file; an upstream API returning an error page instead of JSON; copy-pasting partial JSON; trailing commas or comments (not valid JSON).
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- The 'fromJson' function expects an argument 'json'.
- The 'fromJson' function expects an argument 'json' with type
- Invalid ion: {e.getMessage()}
- Unable to transform to json value '{input}' with type '{inpu
- The 'fromIon' function expects an argument 'ion'.
AI-assisted analysis of kestra-io/kestra@823fada927 (2026-08-14).
Data as JSON: /api/errors/9f243c37eaea35ee.
Report an issue: GitHub.