{"record":{"id":"f96d2559e1b62ff5","repo":"karatelabs/karate","slug":"invalid-json-input-is-null-or-blank","errorCode":null,"errorMessage":"invalid json: input is null or blank","messagePattern":"invalid json: input is null or blank","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/common/Json.java","lineNumber":123,"sourceCode":"        if (any == null) {\n            throw new IllegalArgumentException(\"input must not be null\");\n        }\n        if (any instanceof String s) {\n            if (s.isBlank()) {\n                throw new IllegalArgumentException(\"input string must not be empty or blank\");\n            }\n            return new Json(JsonPath.parse(parseLenient(s)));\n        } else if (any instanceof List || any instanceof Map) {\n            return new Json(JsonPath.parse(any));\n        } else {\n            String json = JSONValue.toJSONString(any);\n            return new Json(JsonPath.parse(json));\n        }\n    }\n\n    public static Object parseLenient(String json) {\n        if (json == null || json.isBlank()) {\n            throw new RuntimeException(\"invalid json: input is null or blank\");\n        }\n        try {\n            Object result = JSONValue.parseKeepingOrder(json);\n            if (!isMapOrList(result)) {\n                throw new RuntimeException(\"invalid json: not a JSON object or array\");\n            }\n            return result;\n        } catch (RuntimeException e) {\n            throw e;\n        } catch (Exception e) {\n            throw new RuntimeException(\"invalid json: \" + e.getMessage(), e);\n        }\n    }\n\n    public static boolean isMapOrList(Object o) {\n        return o instanceof Map || o instanceof List;\n    }\n","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/common/Json.java#L105-L141","documentation":"parseLenient() is Karate's forgiving JSON parser wrapper; before attempting a parse it rejects null or blank input with this RuntimeException. Lenient parsing tolerates loose syntax but cannot do anything with no input at all.","triggerScenarios":"Calling Json.parseLenient(null), parseLenient(\"\"), parseLenient(\" \"), or indirectly via Json.of(blankString).","commonSituations":"Reading empty fixture files, uninitialized string variables, or blank secrets/config entries.","solutions":["Validate the string is non-blank before parsing","Return a default (\"{}\"/\"[]\") or throw a domain-specific error in your code instead","Trace and fix the source of the blank string"],"exampleFix":"// before\nObject o = Json.parseLenient(fileContent);\n// after\nif (fileContent == null || fileContent.isBlank()) throw new IllegalStateException(\"fixture file is empty\");\nObject o = Json.parseLenient(fileContent);","handlingStrategy":"validation","validationCode":"if (json == null || json.isBlank()) { throw new IllegalArgumentException(\"cannot parse blank json input\"); }","typeGuard":null,"tryCatchPattern":"try { Object o = Json.parseLenient(s); } catch (RuntimeException e) { if (\"invalid json: input is null or blank\".equals(e.getMessage())) { o = new java.util.HashMap<>(); } else { throw e; } }","preventionTips":["Guard blank strings before any parse call","Treat empty files/bodies as a distinct case from malformed JSON","Add non-blank assertions in fixtures loading code"],"tags":["java","karate","json","blank-input"],"backgroundTag":"empty-required-field","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"}