karatelabs/karate · error
Invalid literal — expected 'false'
Error message
Invalid literal — expected 'false'
What it means
JsonParser.parseBoolean saw a token that is not the exact literal 'false' (and did not start with 't'). Any casing or spelling deviation — 'False', 'FALSE', 'fals', 'no' — is rejected because JSON defines booleans strictly.
Solutions
- Replace the literal with lowercase 'false'.
- Regenerate the payload with a real JSON serializer so booleans are encoded correctly.
- Pre-normalize boolean-ish strings ('no', 'off', 'FALSE') to JSON booleans when converting other formats.
- Check for truncation if the literal looks like a prefix of 'false'.
Example fix
// before
String json = "{\"debug\": FALSE}";
// after
String json = "{\"debug\": false}"; Defensive patterns
Strategy: validation
Validate before calling
// normalize non-JSON booleans before parsing
raw = raw.replaceAll("\\bFalse\\b", "false")
.replaceAll("\\bFALSE\\b", "false")
.replaceAll("\\b(no|off)\\b(?=\\s*[:,}\\]])", "false"); Try / catch
// Java
try {
Json json = Json.of(raw);
} catch (Exception e) {
if (String.valueOf(e.getMessage()).contains("expected 'false'")) {
raw = raw.replaceAll("\\b(False|FALSE|no|off)\\b", "false");
} else { throw e; }
} Prevention
- Remember YAML-style 'no'/'off' are NOT valid JSON booleans.
- Serialize via a JSON encoder so booleans are rendered correctly.
- Watch for capitalized booleans from SQL/CSV/Python exports.
- Check truncation if the token is a prefix like 'fals'.
When it happens
Trigger: Parsing JSON containing 'False' (Python), 'FALSE' (SQL/CSV exports), 'no'/'off' (YAML-style booleans), or truncated text like '{"ok": fals}' in a value position dispatching to parseBoolean.
Common situations: YAML-to-JSON conversions where unquoted 'no' became an invalid literal; Python json dumps of raw bools via str(); hand-edited files with capitalized booleans; truncated payloads.
Understand the failure class
Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.
Related errors
- Invalid literal — expected 'true'
- Expected ':' after object key
- Expected string key in object
- Invalid literal — expected 'null'
- Invalid number
AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12).
Data as JSON: /api/errors/6af3aace359ab034.
Report an issue: GitHub.
Appendix: source
Thrown at karate-js/src/main/java/io/karatelabs/js/JsonParser.java:335
return v;
} catch (NumberFormatException nfe) {
return new BigInteger(lit);
}
}
private Boolean parseBoolean() {
if (s.charAt(pos) == 't') {
if (pos + 4 <= len && s.charAt(pos + 1) == 'r' && s.charAt(pos + 2) == 'u' && s.charAt(pos + 3) == 'e') {
pos += 4;
return Boolean.TRUE;
}
throw syntaxError("Invalid literal — expected 'true'");
}
if (pos + 5 <= len && s.charAt(pos + 1) == 'a' && s.charAt(pos + 2) == 'l' && s.charAt(pos + 3) == 's' && s.charAt(pos + 4) == 'e') {
pos += 5;
return Boolean.FALSE;
}
throw syntaxError("Invalid literal — expected 'false'");
}
private Object parseNull() {
if (pos + 4 <= len && s.charAt(pos + 1) == 'u' && s.charAt(pos + 2) == 'l' && s.charAt(pos + 3) == 'l') {
pos += 4;
return null;
}
throw syntaxError("Invalid literal — expected 'null'");
}
void skipWs() {
while (pos < len) {
char c = s.charAt(pos);
if (c == ' ' || c == '\t' || c == '\n' || c == '\r') {
pos++;
} else {
return;
}View on GitHub (pinned to a22eb90246)