angular/angular-cli · error · Error
Failed to parse "${this.path}" as JSON AST Object. ${printPa
Error message
Failed to parse "${this.path}" as JSON AST Object. ${printParseErrorCode(error)} at location: ${offset}. What it means
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.
Source
Thrown at packages/schematics/angular/utility/json-file.ts:49
constructor(
private readonly host: Tree,
private readonly path: string,
) {
this.content = this.host.readText(this.path);
this.eol = getEOL(this.content);
}
private _jsonAst: Node | undefined;
private get JsonAst(): Node | undefined {
if (this._jsonAst) {
return this._jsonAst;
}
const errors: ParseError[] = [];
this._jsonAst = parseTree(this.content, errors, { allowTrailingComma: true });
if (errors.length) {
const { error, offset } = errors[0];
throw new Error(
`Failed to parse "${this.path}" as JSON AST Object. ${printParseErrorCode(
error,
)} at location: ${offset}.`,
);
}
return this._jsonAst;
}
get(jsonPath: JSONPath): unknown {
const jsonAstNode = this.JsonAst;
if (!jsonAstNode) {
return undefined;
}
if (jsonPath.length === 0) {
return getNodeValue(jsonAstNode);
}View on GitHub (pinned to bb72145f9a)
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.
Example fix
// before (angular.json)
{ "projects": { "app": { ... ,, } }
// after
{ "projects": { "app": { ... } } } Defensive patterns
Strategy: try-catch
Validate before calling
try { JSON.parse(fs.readFileSync('angular.json', 'utf8')); } catch (e) { /* fix before running schematics */ } Try / catch
try {
await schematicRunner.run(...);
} catch (e) {
if (/Failed to parse .* as JSON/.test(e.message)) {
const m = e.message.match(/at location: (\d+)/);
console.error('Invalid JSON at offset', m && m[1]);
} else throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Failed to parse "${path}" as JSON AST Object. ${printParseEr
- Invalid target: ${JSON.stringify(target)}.
- No builder were found for target ${targetStringFromTarget(ta
- Proxy configuration file ${proxyPath} contains parse errors:
- ${message}
AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30).
Data as JSON: /api/errors/a08fbfaa597575dc.
Report an issue: GitHub.