kestra-io/kestra · error · PebbleException

The 'fromJson' function expects an argument 'json' with type

Error message

The 'fromJson' function expects an argument 'json' with type string.

What it means

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.

Source

Thrown at core/src/main/java/io/kestra/core/runners/pebble/functions/FromJsonFunction.java:39

    }

    @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

  1. Pass a JSON string, typically via readFile() of a .json file or a task output that is text.
  2. If the value is already a structured object, use it directly instead of fromJson().
  3. Verify the upstream expression returns a string before calling fromJson().

Example fix

# before - passing a number literal
obj: "{{ fromJson(42) }}"
# after - pass JSON text
obj: "{{ fromJson(readFile('config.json')) }}"
Defensive patterns

Strategy: type-guard

Type guard

# Pebble-side guard: fromJson only accepts a string.
# {{ (content is string) ? fromJson(content) : content }}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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