karatelabs/karate · error
Invalid number: missing fraction digits
Error message
Invalid number: missing fraction digits
What it means
JSON syntax error raised by parseNumber in JsonParser (via parseValue): after consuming the '.' that starts a fractional part, the parser requires at least one digit; the input at fault is the number literal in the JSON text whose fraction is empty or truncated (e.g. "1." or "1." followed by a non-digit), so the literal cannot form a valid number.
Solutions
- Append the missing fraction digits: '1.' -> '1.0'.
- Fix the formatter that produced the literal so it never emits a trailing '.' without digits.
- Check for payload truncation (size limits, log rotation) cutting the token mid-way.
- Round the value to an integer instead if no fractional part is meaningful.
Example fix
// before
String lit = String.valueOf(value).replaceAll("\\.0+$", "."); // 5.0 -> 5.
// after
String lit = String.valueOf(value).replaceAll("\\.0+$", ""); // 5.0 -> 5 Defensive patterns
Strategy: validation
Validate before calling
// detect numbers ending in a bare decimal point before parsing
if (json.matches(".*\\d\\.([^0-9]|$).*")) {
throw new IllegalArgumentException("JSON number has a decimal point with no fraction digits");
} Try / catch
// Java
try {
Json json = Json.of(raw);
} catch (Exception e) {
if (String.valueOf(e.getMessage()).contains("missing fraction digits")) {
raw = raw.replaceAll("(\\d)\\.(?=[^0-9]|$)", "$1.0");
} else { throw e; }
} Prevention
- Ensure number formatters always emit at least one digit after '.'.
- Avoid stripping trailing zeros with naive regex on serialized JSON.
- Verify payloads are not truncated by size limits or log slicing.
- Lint JSON before parsing in pipelines.
When it happens
Trigger: Parsing JSON containing numbers truncated right after the decimal point: '[1., 2]', '{"price": 9.9.}' misses digits, or '1.' at end of input — commonly produced by toFixed-style formatting that strips trailing zeros, or truncated network payloads.
Common situations: Formatting code that emits 'x.' after removing trailing zeros; log/config files truncated mid-token; template expressions like '{{price}}.' where price lost its decimals.
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 exponent 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/ab60c30f5a4d307f.
Report an issue: GitHub.
Appendix: source
Thrown at karate-js/src/main/java/io/karatelabs/js/JsonParser.java:285
pos++;
} else if (c >= '1' && c <= '9') {
pos++;
while (pos < len && (s.charAt(pos) >= '0' && s.charAt(pos) <= '9')) {
pos++;
}
} else {
throw syntaxError("Invalid number");
}
// fraction
if (pos < len && s.charAt(pos) == '.') {
isFloat = true;
pos++;
int fracStart = pos;
while (pos < len && (s.charAt(pos) >= '0' && s.charAt(pos) <= '9')) {
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);View on GitHub (pinned to a22eb90246)