{"record":{"id":"a08fbfaa597575dc","repo":"angular/angular-cli","slug":"failed-to-parse-this-path-as-json-ast-object","errorCode":null,"errorMessage":"Failed to parse \"${this.path}\" as JSON AST Object. ${printParseErrorCode(error)} at location: ${offset}.","messagePattern":"Failed to parse \"(.+?)\" as JSON AST Object\\. (.+?) at location: (.+?)\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/schematics/angular/utility/json-file.ts","lineNumber":49,"sourceCode":"  constructor(\n    private readonly host: Tree,\n    private readonly path: string,\n  ) {\n    this.content = this.host.readText(this.path);\n    this.eol = getEOL(this.content);\n  }\n\n  private _jsonAst: Node | undefined;\n  private get JsonAst(): Node | undefined {\n    if (this._jsonAst) {\n      return this._jsonAst;\n    }\n\n    const errors: ParseError[] = [];\n    this._jsonAst = parseTree(this.content, errors, { allowTrailingComma: true });\n    if (errors.length) {\n      const { error, offset } = errors[0];\n      throw new Error(\n        `Failed to parse \"${this.path}\" as JSON AST Object. ${printParseErrorCode(\n          error,\n        )} at location: ${offset}.`,\n      );\n    }\n\n    return this._jsonAst;\n  }\n\n  get(jsonPath: JSONPath): unknown {\n    const jsonAstNode = this.JsonAst;\n    if (!jsonAstNode) {\n      return undefined;\n    }\n\n    if (jsonPath.length === 0) {\n      return getNodeValue(jsonAstNode);\n    }","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/schematics/angular/utility/json-file.ts#L31-L67","documentation":"The JsonAst helper parses a JSON file (angular.json/workspace config) into an AST with the JSON parser. When the file content contains a syntax error, the parse records errors and the class throws with the error code and byte offset of the first problem.","triggerScenarios":"Any schematic or builder reading a JSON file (typically angular.json) whose content fails JSON parsing — trailing content, unquoted keys, stray commas, comments, or truncated edits by earlier tools.","commonSituations":"Manual edits to angular.json introducing invalid JSON (comments, missing quotes); merge conflicts left markers like <<<<<<<; scripts rewriting the config and truncating it; non-UTF8 or BOM issues.","solutions":["Open the file at the reported offset, fix the JSON syntax error, and re-run the command.","Validate the file with a JSON linter or `node -e \"JSON.parse(require('fs').readFileSync('angular.json'))\"`.","Restore angular.json from git (`git checkout -- angular.json`) if the file was corrupted by tooling."],"exampleFix":"// before (angular.json)\n{ \"projects\": { \"app\": { ... ,, } }\n// after\n{ \"projects\": { \"app\": { ... } } }","handlingStrategy":"try-catch","validationCode":"try { JSON.parse(fs.readFileSync('angular.json', 'utf8')); } catch (e) { /* fix before running schematics */ }","typeGuard":null,"tryCatchPattern":"try {\n  await schematicRunner.run(...);\n} catch (e) {\n  if (/Failed to parse .* as JSON/.test(e.message)) {\n    const m = e.message.match(/at location: (\\d+)/);\n    console.error('Invalid JSON at offset', m && m[1]);\n  } else throw e;\n}","preventionTips":["Validate angular.json after every manual edit (JSON parse or linter).","Never leave merge-conflict markers in workspace config files.","Edit angular.json with `ng config` instead of by hand."],"tags":["angular","json","parse-error","workspace-config"],"backgroundTag":"json-parse-failed","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}