{"record":{"id":"08693cedf45d3187","repo":"abhigyanpatwari/GitNexus","slug":"gitnexus-rc-filename-is-not-valid-json-err","errorCode":null,"errorMessage":"${GITNEXUS_RC_FILENAME} is not valid JSON: ${(err as Error).message}. Expected a JSON object such as {\"defaultBranch\": \"develop\", \"skipContextFiles\": true}.","messagePattern":"(.+?) is not valid JSON: (.+?)\\. Expected a JSON object such as (.+?)\\.","errorType":"validation","errorClass":"GitNexusRcError","httpStatus":null,"severity":"error","filePath":"gitnexus/src/cli/analyze-config.ts","lineNumber":400,"sourceCode":"    throw new GitNexusRcError(`Could not read ${GITNEXUS_RC_FILENAME}: ${(err as Error).message}`);\n  }\n  return raw === null ? undefined : parseAnalyzeConfig(raw);\n}\n\nfunction parseAnalyzeConfig(rawInput: string): Partial<AnalyzeOptions> {\n  let raw = rawInput;\n\n  // Strip a leading UTF-8 BOM: Node's 'utf-8' decode keeps it, and JSON.parse\n  // then fails with a confusing \"Unexpected token\" on an otherwise-valid file\n  // (#1996 tri-review). Only one leading BOM is stripped; in-string control\n  // rejection still applies to the parsed values.\n  if (raw.charCodeAt(0) === 0xfeff) raw = raw.slice(1);\n\n  let parsed: unknown;\n  try {\n    parsed = JSON.parse(raw);\n  } catch (err) {\n    throw new GitNexusRcError(\n      `${GITNEXUS_RC_FILENAME} is not valid JSON: ${(err as Error).message}. ` +\n        `Expected a JSON object such as {\"defaultBranch\": \"develop\", \"skipContextFiles\": true}.`,\n    );\n  }\n\n  if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {\n    throw new GitNexusRcError(`${GITNEXUS_RC_FILENAME} must contain a JSON object.`);\n  }\n\n  const obj = parsed as Record<string, unknown>;\n  const flat = normalizeLevel(obj, { allowNestedKey: true });\n\n  let nested: Partial<AnalyzeOptions> = {};\n  if (Object.prototype.hasOwnProperty.call(obj, NESTED_KEY)) {\n    const nestedRaw = obj[NESTED_KEY];\n    if (nestedRaw === null || typeof nestedRaw !== 'object' || Array.isArray(nestedRaw)) {\n      throw new GitNexusRcError(`${GITNEXUS_RC_FILENAME} \"${NESTED_KEY}\" must be a JSON object.`);\n    }","sourceCodeStart":382,"sourceCodeEnd":418,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/ac9a4e9abd8fd3058c070b72c23402a4f887929a/gitnexus/src/cli/analyze-config.ts#L382-L418","documentation":"The rc file must be strict JSON. After stripping one leading UTF-8 BOM (a deliberate fix so valid files with a BOM still parse), JSON.parse failures throw this error with the parser's message and an example of the expected object shape. Trailing commas, comments, single quotes, or unquoted keys all fail here.","triggerScenarios":".gitnexusrc containing JSONC (// comments), a trailing comma after the last key, single-quoted strings, unquoted keys, or stray characters after the closing brace; JSON.parse(raw) throws at analyze-config.ts:392.","commonSituations":"Hand-editing and commenting values for later; Windows editors appending a BOM plus a comment; merging conflicts that leave a stray comma; pasting YAML fragments.","solutions":["Paste the file into a JSON validator — the parser message pinpoints the offending position","Remove comments, trailing commas, and quote all keys/strings with double quotes","Prefer deleting a key over commenting it out; keep the example shape {\"defaultBranch\": \"develop\", \"skipContextFiles\": true}"],"exampleFix":"// before (.gitnexusrc)\n{\n  \"defaultBranch\": \"develop\", // mainline\n  \"skipSkills\": true,\n}\n// after\n{\n  \"defaultBranch\": \"develop\",\n  \"skipSkills\": true\n}","handlingStrategy":"validation","validationCode":"// Fail fast with a clearer message than the CLI's:\nimport { readFileSync } from 'node:fs';\nconst raw = readFileSync('.gitnexusrc', 'utf8').replace(/^\\uFEFF/, '');\ntry {\n  JSON.parse(raw);\n} catch (e) {\n  throw new Error(`.gitnexusrc is not valid JSON: ${(e as Error).message}`);\n}","typeGuard":null,"tryCatchPattern":"catch (err) {\n  if (err instanceof GitNexusRcError && err.message.includes('not valid JSON')) {\n    // run the file through `node -e 'JSON.parse(require(\"fs\").readFileSync(\".gitnexusrc\",\"utf8\"))'` to see the position\n  }\n}","preventionTips":["Strict JSON only: no comments, no trailing commas, double quotes everywhere","Validate .gitnexusrc in a pre-commit hook (e.g. prettier --check or jq)","A single leading BOM is tolerated; anything else must be clean JSON"],"tags":["config","json","parse-error","gitnexusrc"],"backgroundTag":"json-parse-error","analyzedSha":"ac9a4e9abd8fd3058c070b72c23402a4f887929a","analyzedAt":"2026-08-20T23:29:22.980Z","contentChangedAt":"2026-08-20T23:29:22.980Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}