{"record":{"id":"cda8cfdcc22ee1c9","repo":"karatelabs/karate","slug":"missing-argument-for-paramjson","errorCode":null,"errorMessage":"missing argument for paramJson()","messagePattern":"missing argument for paramJson\\(\\)","errorType":"validation","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/http/HttpRequest.java","lineNumber":582,"sourceCode":"                throw new RuntimeException(\"missing argument for paramInt()\");\n            }\n        };\n    }\n\n    private JavaInvokable paramJson() {\n        return args -> {\n            if (args.length > 0) {\n                String val = getParam(args[0] + \"\");\n                if (val == null) {\n                    return null;\n                }\n                try {\n                    return Json.of(val).value();\n                } catch (Exception e) {\n                    return val; // return raw string if not valid JSON\n                }\n            } else {\n                throw new RuntimeException(\"missing argument for paramJson()\");\n            }\n        };\n    }\n\n    /**\n     * 1-arg form: {@code request.header('X')} — returns the last value (String) or null.\n     * 2-arg form: {@code request.header('X', 'v')} — sets the header. {@code null}\n     * value removes the header. {@code List} value sets all values.\n     */\n    private JavaInvokable header() {\n        return args -> {\n            if (args.length == 0) {\n                throw new RuntimeException(\"missing argument for header()\");\n            }\n            String name = args[0] + \"\";\n            if (args.length == 1) {\n                return getHeader(name);\n            }","sourceCodeStart":564,"sourceCodeEnd":600,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/http/HttpRequest.java#L564-L600","documentation":"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()'.","triggerScenarios":"Calling request.paramJson() with no arguments instead of request.paramJson('payload').","commonSituations":"Dropped argument in scripts, empty variable interpolation, assuming the method parses all params at once.","solutions":["Pass the parameter name: request.paramJson('filter')","Ensure the name variable is populated before the call","If the value should always be JSON, validate the parameter content separately (non-JSON values are returned raw)"],"exampleFix":"// before\nvar f = request.paramJson();\n// after\nvar f = request.paramJson('filter');","handlingStrategy":"type-guard","validationCode":"if (name == null || name.isEmpty()) throw new IllegalArgumentException(\"param name required\");","typeGuard":"function requireArg(name, args) { if (args == null || args.length === 0) throw new Error('missing argument for paramJson()'); return name; }","tryCatchPattern":"try { var f = request.paramJson('filter'); } catch (RuntimeException e) { /* fix call site: name argument missing */ }","preventionTips":["Always pass the parameter name to paramJson()","Validate interpolated name variables before use","Remember non-JSON values are returned as raw strings — validate payload shape downstream"],"tags":["http","arguments","api-misuse","json"],"backgroundTag":"missing-required-argument","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-16T19:17:19.609Z"}