{"record":{"id":"ab60c30f5a4d307f","repo":"karatelabs/karate","slug":"invalid-number-missing-fraction-digits","errorCode":null,"errorMessage":"Invalid number: missing fraction digits","messagePattern":"Invalid number: missing fraction digits","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/js/JsonParser.java","lineNumber":285,"sourceCode":"                pos++;\n            } else if (c >= '1' && c <= '9') {\n                pos++;\n                while (pos < len && (s.charAt(pos) >= '0' && s.charAt(pos) <= '9')) {\n                    pos++;\n                }\n            } else {\n                throw syntaxError(\"Invalid number\");\n            }\n            // fraction\n            if (pos < len && s.charAt(pos) == '.') {\n                isFloat = true;\n                pos++;\n                int fracStart = pos;\n                while (pos < len && (s.charAt(pos) >= '0' && s.charAt(pos) <= '9')) {\n                    pos++;\n                }\n                if (pos == fracStart) {\n                    throw syntaxError(\"Invalid number: missing fraction digits\");\n                }\n            }\n            // exponent\n            if (pos < len && (s.charAt(pos) == 'e' || s.charAt(pos) == 'E')) {\n                isFloat = true;\n                pos++;\n                if (pos < len && (s.charAt(pos) == '+' || s.charAt(pos) == '-')) {\n                    pos++;\n                }\n                int expStart = pos;\n                while (pos < len && (s.charAt(pos) >= '0' && s.charAt(pos) <= '9')) {\n                    pos++;\n                }\n                if (pos == expStart) {\n                    throw syntaxError(\"Invalid number: missing exponent digits\");\n                }\n            }\n            String lit = s.substring(start, pos);","sourceCodeStart":267,"sourceCodeEnd":303,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/js/JsonParser.java#L267-L303","documentation":"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.","triggerScenarios":"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.","commonSituations":"Formatting code that emits 'x.' after removing trailing zeros; log/config files truncated mid-token; template expressions like '{{price}}.' where price lost its decimals.","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."],"exampleFix":"// before\nString lit = String.valueOf(value).replaceAll(\"\\\\.0+$\", \".\"); // 5.0 -> 5.\n// after\nString lit = String.valueOf(value).replaceAll(\"\\\\.0+$\", \"\"); // 5.0 -> 5","handlingStrategy":"validation","validationCode":"// detect numbers ending in a bare decimal point before parsing\nif (json.matches(\".*\\\\d\\\\.([^0-9]|$).*\")) {\n    throw new IllegalArgumentException(\"JSON number has a decimal point with no fraction digits\");\n}","typeGuard":null,"tryCatchPattern":"// Java\ntry {\n    Json json = Json.of(raw);\n} catch (Exception e) {\n    if (String.valueOf(e.getMessage()).contains(\"missing fraction digits\")) {\n        raw = raw.replaceAll(\"(\\\\d)\\\\.(?=[^0-9]|$)\", \"$1.0\");\n    } else { throw e; }\n}","preventionTips":["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."],"tags":["json","parser","syntax-error","number-literal"],"backgroundTag":"json-parse-error","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"}