{"record":{"id":"e3c9bf226e9d8348","repo":"karatelabs/karate","slug":"input-string-must-not-be-empty-or-blank","errorCode":null,"errorMessage":"input string must not be empty or blank","messagePattern":"input string must not be empty or blank","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/common/Json.java","lineNumber":110,"sourceCode":"    private String prefix(String path) {\n        return path.charAt(0) == '$' ? path : prefix + path;\n    }\n\n    public static Json object() {\n        return new Json(JsonPath.parse(\"{}\"));\n    }\n\n    public static Json array() {\n        return new Json(JsonPath.parse(\"[]\"));\n    }\n\n    public static Json of(Object any) {\n        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\");","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/common/Json.java#L92-L128","documentation":"When Json.of() receives a String it must contain actual JSON content; a null, empty, or whitespace-only string cannot be parsed into a document, so it throws immediately. This is distinct from malformed JSON — the string has no content at all.","triggerScenarios":"Json.of(\"\") or Json.of(\"   \"), or Json.of(someStringVariable) where the string came from an empty file, blank env var, or empty response body.","commonSituations":"Empty config files, blank environment variables, or HTTP 204/empty-body responses fed into Json.of().","solutions":["Guard with `s != null && !s.isBlank()` before calling Json.of","Provide a default JSON string like \"{}\" or \"[]\" when input is blank","Fix the source producing the blank string (file/env/response)"],"exampleFix":"// before\nJson json = Json.of(configString);\n// after\nJson json = (configString == null || configString.isBlank()) ? Json.of(\"{}\") : Json.of(configString);","handlingStrategy":"validation","validationCode":"if (s == null || s.isBlank()) { s = \"{}\"; }","typeGuard":"boolean isNonBlankString(Object o) { return o instanceof String s && !s.isBlank(); }","tryCatchPattern":"try { Json json = Json.of(str); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"must not be empty or blank\")) { json = Json.of(\"{}\"); } else { throw e; } }","preventionTips":["Validate files/env vars/response bodies are non-blank before parsing","Default blank inputs to \"{}\" or \"[]\" at read time","Log the raw source when it is blank to catch upstream regressions"],"tags":["java","karate","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"}