{"record":{"id":"cb484d0c9eef7788","repo":"angular/angular-cli","slug":"failed-to-parse-path-as-json-ast-object-pr-cb484d","errorCode":null,"errorMessage":"Failed to parse \"${path}\" as JSON AST Object. ${printParseErrorCode(error)} at location: ${offset}.","messagePattern":"Failed to parse \"(.+?)\" as JSON AST Object\\. (.+?) at location: (.+?)\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/angular_devkit/schematics/tools/file-system-utility.ts","lineNumber":30,"sourceCode":"import { FileDoesNotExistException } from '../src/exception/exception';\n\nexport function readJsonFile(path: string): JsonValue {\n  let data;\n  try {\n    data = readFileSync(path, 'utf-8');\n  } catch (e) {\n    if (e && typeof e === 'object' && 'code' in e && e.code === 'ENOENT') {\n      throw new FileDoesNotExistException(path);\n    }\n    throw e;\n  }\n\n  const errors: ParseError[] = [];\n  const content = parse(data, errors, { allowTrailingComma: true }) as JsonValue;\n\n  if (errors.length) {\n    const { error, offset } = errors[0];\n    throw new Error(\n      `Failed to parse \"${path}\" as JSON AST Object. ${printParseErrorCode(\n        error,\n      )} at location: ${offset}.`,\n    );\n  }\n\n  return content;\n}\n","sourceCodeStart":12,"sourceCodeEnd":39,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/angular_devkit/schematics/tools/file-system-utility.ts#L12-L39","documentation":"readJsonFile parses the file with the JSON AST parser (jsonc-parser `parse`) collecting syntax errors; if any errors are reported it throws an Error naming the file, the parse error code, and the character offset. Raised when the JSON file exists but is malformed.","triggerScenarios":"readJsonFile on a file whose contents are invalid JSON — parse() pushes into `errors` and the first error is thrown with printParseErrorCode and the offset.","commonSituations":"Hand-edited collection.json/schema.json with a missing comma, unquoted key, or stray bracket; a merge conflict marker left in the file; a template placeholder ({{ }}) unrendered in a JSON file; saving a JSON5 feature (comments) unsupported by strict parse settings.","solutions":["Use the offset in the message to find the exact broken location in the file (count characters or use an editor's Go to Offset).","Fix the JSON syntax error (missing comma/quote/brace, conflict markers, placeholder text).","Validate the file with `node -e \"JSON.parse(require('fs').readFileSync('<path>','utf8'))\"` or an editor JSON linter before re-running.","If generated, regenerate the file from source instead of patching the output."],"exampleFix":"// before (collection.json)\n{ \"schematics\": { \"a\": { \"factory\": \"./a#index\" } \"description\": \"x\" } }\n// after (comma added)\n{ \"schematics\": { \"a\": { \"factory\": \"./a#index\", \"description\": \"x\" } } }","handlingStrategy":"validation","validationCode":"try {\n  JSON.parse(readFileSync(path, 'utf8'));\n} catch (e) {\n  throw new Error(`${path} is not valid JSON: ${(e as Error).message}`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  const json = readJsonFile(path);\n} catch (e) {\n  if (String(e.message).startsWith('Failed to parse')) {\n    const m = e.message.match(/location: (\\d+)/);\n    console.error(`JSON syntax error in ${path} near offset ${m?.[1]} — fix and retry`);\n    process.exitCode = 1;\n  } else throw e;\n}","preventionTips":["Enable JSON linting/format-on-save in editors and validate all JSON in CI.","Search files for merge conflict markers (<<<<<<<) before committing.","Never hand-write JSON with comments or trailing commas outside parser-supported settings; prefer jsonc only where supported."],"tags":["json","parsing","configuration"],"backgroundTag":"json-parse-failed","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}