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

  1. Validate the string is well-formed JSON (use jq or a linter) before passing it.
  2. If the source is YAML or another format, convert it to JSON first or use the appropriate parser.
  3. Handle API error responses (e.g. check status/content-type) before parsing the body as JSON.
  4. 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

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

Related errors


AI-assisted analysis of kestra-io/kestra@823fada927 (2026-08-14). Data as JSON: /api/errors/9f243c37eaea35ee. Report an issue: GitHub.