{"record":{"id":"d692da1d9ed86a8b","repo":"karatelabs/karate","slug":"invalid-config-expected-json-object","errorCode":null,"errorMessage":"Invalid config: expected JSON object","messagePattern":"Invalid config: expected JSON object","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/core/KaratePom.java","lineNumber":197,"sourceCode":"        try {\n            String content = Files.readString(configPath);\n            return parse(content);\n        } catch (Exception e) {\n            throw new RuntimeException(\"Failed to load config from: \" + configPath, e);\n        }\n    }\n\n    /**\n     * Parse configuration from a JSON string.\n     *\n     * @param json JSON string\n     * @return parsed KaratePom\n     * @throws RuntimeException if JSON is invalid\n     */\n    public static KaratePom parse(String json) {\n        Json j = Json.of(json);\n        if (!j.isObject()) {\n            throw new RuntimeException(\"Invalid config: expected JSON object\");\n        }\n        KaratePom config = new KaratePom();\n\n        // Parse paths\n        j.<List<String>>getOptional(\"paths\").ifPresent(config::setPaths);\n\n        // Parse tags\n        j.<List<String>>getOptional(\"tags\").ifPresent(config::setTags);\n\n        // Parse simple fields\n        j.<String>getOptional(\"env\").ifPresent(config::setEnv);\n        j.<Integer>getOptional(\"threads\").ifPresent(config::setThreads);\n        j.<String>getOptional(\"scenarioName\").ifPresent(config::setScenarioName);\n        j.<String>getOptional(\"configDir\").ifPresent(config::setConfigDir);\n        j.<Boolean>getOptional(\"dryRun\").ifPresent(config::setDryRun);\n        j.<Boolean>getOptional(\"clean\").ifPresent(config::setClean);\n        j.<String>getOptional(\"workingDir\").ifPresent(config::setWorkingDir);\n","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/core/KaratePom.java#L179-L215","documentation":"KaratePom.parse(json) requires the karate-pom configuration to be a JSON object; if the supplied text parses as anything other than an object (array, string, number, or invalid JSON surfacing as a non-object) it throws this error.","triggerScenarios":"Passing a JSON array, bare scalar, empty string, or otherwise non-object content to KaratePom.parse() — directly or via load() of a malformed karate-pom.json.","commonSituations":"Config file accidentally saved as an array of settings or containing only a comment; file truncated to empty; pasting YAML instead of JSON; BOM or encoding garbage corrupting the JSON.","solutions":["Ensure the config root is a JSON object starting with { and ending with }","Validate the file with a JSON linter/parser before use","Check for empty or truncated files and restore full content","Convert YAML/other formats to JSON"],"exampleFix":"// before (karate-pom.json)\n[\"src/test/java\"]\n// after\n{\n  \"paths\": [\"src/test/java\"]\n}","handlingStrategy":"validation","validationCode":"// Validate JSON root is an object before parsing\nJson j = Json.of(Files.readString(path));\nif (!j.isObject()) throw new IllegalStateException(\"karate-pom.json root must be a JSON object\");","typeGuard":"static boolean isJsonObject(String json) { Json j = Json.of(json); return j.isObject(); }","tryCatchPattern":"try {\n    KaratePom pom = KaratePom.parse(json);\n} catch (RuntimeException e) {\n    throw new IllegalStateException(\"karate-pom must be a JSON object, got: \" + json.getClass(), e);\n}","preventionTips":["Keep the config root as a { ... } object","Lint the file with a JSON validator in CI","Reject empty/truncated files and stray BOMs"],"tags":["json","config","validation"],"backgroundTag":"schema-validation-failed","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"}