karatelabs/karate · error · RuntimeException

missing argument for paramJson()

Error message

missing argument for paramJson()

What it means

The request.paramJson() invokable requires one argument naming the parameter; its value is parsed as JSON (falling back to the raw string if not valid JSON). With zero arguments it throws RuntimeException 'missing argument for paramJson()'.

Solutions

  1. Pass the parameter name: request.paramJson('filter')
  2. Ensure the name variable is populated before the call
  3. If the value should always be JSON, validate the parameter content separately (non-JSON values are returned raw)

Example fix

// before
var f = request.paramJson();
// after
var f = request.paramJson('filter');
Defensive patterns

Strategy: type-guard

Validate before calling

if (name == null || name.isEmpty()) throw new IllegalArgumentException("param name required");

Type guard

function requireArg(name, args) { if (args == null || args.length === 0) throw new Error('missing argument for paramJson()'); return name; }

Try / catch

try { var f = request.paramJson('filter'); } catch (RuntimeException e) { /* fix call site: name argument missing */ }

Prevention

When it happens

Trigger: Calling request.paramJson() with no arguments instead of request.paramJson('payload').

Common situations: Dropped argument in scripts, empty variable interpolation, assuming the method parses all params at once.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12). Data as JSON: /api/errors/cda8cfdcc22ee1c9. Report an issue: GitHub.

Appendix: source

Thrown at karate-core/src/main/java/io/karatelabs/http/HttpRequest.java:582

                throw new RuntimeException("missing argument for paramInt()");
            }
        };
    }

    private JavaInvokable paramJson() {
        return args -> {
            if (args.length > 0) {
                String val = getParam(args[0] + "");
                if (val == null) {
                    return null;
                }
                try {
                    return Json.of(val).value();
                } catch (Exception e) {
                    return val; // return raw string if not valid JSON
                }
            } else {
                throw new RuntimeException("missing argument for paramJson()");
            }
        };
    }

    /**
     * 1-arg form: {@code request.header('X')} — returns the last value (String) or null.
     * 2-arg form: {@code request.header('X', 'v')} — sets the header. {@code null}
     * value removes the header. {@code List} value sets all values.
     */
    private JavaInvokable header() {
        return args -> {
            if (args.length == 0) {
                throw new RuntimeException("missing argument for header()");
            }
            String name = args[0] + "";
            if (args.length == 1) {
                return getHeader(name);
            }

View on GitHub (pinned to a22eb90246)