{"record":{"id":"c76d1cc0bc3050e8","repo":"karatelabs/karate","slug":"invalid-number-missing-exponent-digits","errorCode":null,"errorMessage":"Invalid number: missing exponent digits","messagePattern":"Invalid number: missing exponent digits","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/js/JsonParser.java","lineNumber":300,"sourceCode":"                    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);\n            if (isFloat) {\n                return Double.parseDouble(lit);\n            }\n            // integer literal — narrow to Integer / Long / BigInteger to match\n            // the json-smart contract (see JsonNumberContractTest).\n            // Negative-zero integer form: json-smart returns Integer 0 (sign\n            // lost). We match that to keep instanceof-Integer call sites in\n            // karate-core stable (OAuth2Token.fromMap, W3cDriver, etc.).\n            try {\n                long v = Long.parseLong(lit);\n                if (v >= Integer.MIN_VALUE && v <= Integer.MAX_VALUE) {\n                    return (int) v;\n                }\n                return v;\n            } catch (NumberFormatException nfe) {","sourceCodeStart":282,"sourceCodeEnd":318,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/js/JsonParser.java#L282-L318","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nString json = \"{\\\"atoms\\\": 6.02e}\";\n// after\nString json = \"{\\\"atoms\\\": 6.02e23}\";","handlingStrategy":"validation","validationCode":"// detect exponents without digits before parsing\nif (json.matches(\".*[eE][-+]?([^0-9]|$).*\")) {\n    throw new IllegalArgumentException(\"JSON number has an exponent with no 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 exponent digits\")) {\n        raw = raw.replaceAll(\"([eE][-+]?)\\\\s*(?=[,}\\\\]]|$)\", \"${1}0\");\n    } else { throw e; }\n}","preventionTips":["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."],"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"}