karatelabs/karate · error
Invalid number: missing exponent digits
Error message
Invalid number: missing exponent digits
What it means
JSON syntax error in parseNumber: an 'e'/'E' exponent marker was found but no digits followed (optionally after a sign), so the number literal is invalid. Fires on input like '1e' or '1e+'; add the exponent digits.
Solutions
- Complete the exponent with its digits: '1e' -> '1e0', '2.5E-' -> '2.5E-1'.
- Verify the source payload is not being truncated (increase buffer/response size limits).
- Use plain decimal notation if the exponent is not needed.
- Run the payload through a strict JSON validator before parsing to localize the fault.
Example fix
// before
String json = "{\"atoms\": 6.02e}";
// after
String json = "{\"atoms\": 6.02e23}"; Defensive patterns
Strategy: validation
Validate before calling
// detect exponents without digits before parsing
if (json.matches(".*[eE][-+]?([^0-9]|$).*")) {
throw new IllegalArgumentException("JSON number has an exponent with no digits");
} Try / catch
// Java
try {
Json json = Json.of(raw);
} catch (Exception e) {
if (String.valueOf(e.getMessage()).contains("missing exponent digits")) {
raw = raw.replaceAll("([eE][-+]?)\\s*(?=[,}\\]]|$)", "${1}0");
} else { throw e; }
} Prevention
- Complete exponent literals ('1e0' is valid; '1e' is not).
- Beware fixed-size buffers and streaming limits truncating scientific notation.
- Prefer plain decimal notation when exponent values are static.
- Run payloads through a strict JSON validator upstream.
When it happens
Trigger: Parsing JSON with scientific-notation numbers truncated after 'e' or 'e-' — e.g. '[1e]', '{"v": 3e,}', or strings cut off mid-token by fixed-size buffers or streaming limits.
Common situations: Cut-and-paste from scientific output where the exponent was on the next line; truncated HTTP responses; hand-typed values like '1e9' with the '9' accidentally deleted.
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 number: bare '-'
- Invalid number
- Invalid number: missing fraction digits
- Unexpected token ' ' in JSON
- Expected string key in object
AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12).
Data as JSON: /api/errors/c76d1cc0bc3050e8.
Report an issue: GitHub.
Appendix: source
Thrown at karate-js/src/main/java/io/karatelabs/js/JsonParser.java:300
pos++;
}
if (pos == fracStart) {
throw syntaxError("Invalid number: missing fraction digits");
}
}
// exponent
if (pos < len && (s.charAt(pos) == 'e' || s.charAt(pos) == 'E')) {
isFloat = true;
pos++;
if (pos < len && (s.charAt(pos) == '+' || s.charAt(pos) == '-')) {
pos++;
}
int expStart = pos;
while (pos < len && (s.charAt(pos) >= '0' && s.charAt(pos) <= '9')) {
pos++;
}
if (pos == expStart) {
throw syntaxError("Invalid number: missing exponent digits");
}
}
String lit = s.substring(start, pos);
if (isFloat) {
return Double.parseDouble(lit);
}
// integer literal — narrow to Integer / Long / BigInteger to match
// the json-smart contract (see JsonNumberContractTest).
// Negative-zero integer form: json-smart returns Integer 0 (sign
// lost). We match that to keep instanceof-Integer call sites in
// karate-core stable (OAuth2Token.fromMap, W3cDriver, etc.).
try {
long v = Long.parseLong(lit);
if (v >= Integer.MIN_VALUE && v <= Integer.MAX_VALUE) {
return (int) v;
}
return v;
} catch (NumberFormatException nfe) {View on GitHub (pinned to a22eb90246)