{"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":392,"sourceCode":"  let raw: string;\n  try {\n    raw = fs.readFileSync(filePath, 'utf-8');\n  } catch (err) {\n    if ((err as NodeJS.ErrnoException)?.code === 'ENOENT') return undefined;\n    throw new GitNexusRcError(`Could not read ${GITNEXUS_RC_FILENAME}: ${(err as Error).message}`);\n  }\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":374,"sourceCodeEnd":410,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/d540b00184d71a896261ee02670da9a92d59d8f7/gitnexus/src/cli/analyze-config.ts#L374-L410","documentation":"`.gitnexusrc` was read and a leading UTF-8 BOM was already stripped, but `JSON.parse` still failed — genuine JSON syntax error. The error appends Node's parse message and a correct example object so the fix is obvious. All keys must be double-quoted, no trailing commas, no comments.","triggerScenarios":"Trailing comma { \"a\": 1, }; unquoted keys { a: 1 }; single-quoted values { 'a': 'b' }; a // comment; a stray control character inside a string.","commonSituations":"Hand-editing and treating the file like a JS object literal; copy-pasting from a JS source or README that used unquoted keys; JSON5/JSONC syntax in a strict-JSON file.","solutions":["Validate the file standalone: node -e 'JSON.parse(require(\"fs\").readFileSync(\".gitnexusrc\",\"utf8\"))'.","Double-quote all keys and string values; remove trailing commas and comments.","Re-save as UTF-8 without BOM (a leading BOM is already tolerated, but strip it to be safe)."],"exampleFix":"// before\n{defaultBranch: \"develop\",}\n// after\n{\"defaultBranch\": \"develop\"}","handlingStrategy":"validation","validationCode":"// Validate JSON before running gitnexus analyze\nconst raw = require('node:fs').readFileSync('.gitnexusrc', 'utf8');\nJSON.parse(raw); // throws with a precise location if invalid","typeGuard":null,"tryCatchPattern":"try {\n  loadAnalyzeConfig(repoRoot);\n} catch (e) {\n  if (e instanceof GitNexusRcError && e.message.includes('is not valid JSON')) {\n    // run `node -e 'JSON.parse(...)'` for the caret position\n  }\n  throw e;\n}","preventionTips":["Use double-quoted keys, no trailing commas, no comments.","Run `node -e JSON.parse` on .gitnexusrc in pre-commit."],"tags":["config","gitnexusrc","json","validation"],"backgroundTag":null,"analyzedSha":"d540b00184d71a896261ee02670da9a92d59d8f7","analyzedAt":"2026-08-12T19:50:25.132Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}