karatelabs/karate · error · RuntimeException
invalid json: input is null or blank
Error message
invalid json: input is null or blank
What it means
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.
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
Example fix
// before
Object o = Json.parseLenient(fileContent);
// after
if (fileContent == null || fileContent.isBlank()) throw new IllegalStateException("fixture file is empty");
Object o = Json.parseLenient(fileContent); Defensive patterns
Strategy: validation
Validate before calling
if (json == null || json.isBlank()) { throw new IllegalArgumentException("cannot parse blank json input"); } Try / catch
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; } } Prevention
- 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
When it happens
Trigger: Calling Json.parseLenient(null), parseLenient(""), parseLenient(" "), or indirectly via Json.of(blankString).
Common situations: Reading empty fixture files, uninitialized string variables, or blank secrets/config entries.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- input string must not be empty or blank
- invalid json: not a JSON object or array
- invalid json
- input must not be null
- cannot replace root path $
AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12).
Data as JSON: /api/errors/f96d2559e1b62ff5.
Report an issue: GitHub.
Appendix: source
Thrown at karate-core/src/main/java/io/karatelabs/common/Json.java:123
if (any == null) {
throw new IllegalArgumentException("input must not be null");
}
if (any instanceof String s) {
if (s.isBlank()) {
throw new IllegalArgumentException("input string must not be empty or blank");
}
return new Json(JsonPath.parse(parseLenient(s)));
} else if (any instanceof List || any instanceof Map) {
return new Json(JsonPath.parse(any));
} else {
String json = JSONValue.toJSONString(any);
return new Json(JsonPath.parse(json));
}
}
public static Object parseLenient(String json) {
if (json == null || json.isBlank()) {
throw new RuntimeException("invalid json: input is null or blank");
}
try {
Object result = JSONValue.parseKeepingOrder(json);
if (!isMapOrList(result)) {
throw new RuntimeException("invalid json: not a JSON object or array");
}
return result;
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException("invalid json: " + e.getMessage(), e);
}
}
public static boolean isMapOrList(Object o) {
return o instanceof Map || o instanceof List;
}
View on GitHub (pinned to a22eb90246)