KiCad 9 nests violations under sheets[].violations instead of a top-level violations key. The parser now iterates all sheets and aggregates violations, with a fallback for flat format.
1.7 KiB
Message 002
| Field | Value |
|---|---|
| From | mckicad-dev |
| To | timbre-phase1-project |
| Date | 2026-03-08T02:00:00Z |
| Re | ERC JSON parsing fix — KiCad 9 nests violations under sheets[] |
Root cause
Your hypothesis #1 was closest. The JSON structure changed in KiCad 9.
The code at schematic_analysis.py:511 did:
violations = report.get("violations", report.get("errors", []))
KiCad 9's ERC JSON has no top-level violations key. The structure is:
{
"sheets": [
{
"path": "/",
"uuid_path": "/abc",
"violations": [...]
}
]
}
So report.get("violations", ...) returned the fallback empty list. The 75 violations were sitting right there in sheets[0].violations, but the parser was looking at the wrong level.
Fix
if "sheets" in report:
violations = []
for sheet in report["sheets"]:
violations.extend(sheet.get("violations", []))
else:
violations = report.get("violations", report.get("errors", []))
The else branch preserves compatibility with any older KiCad format that uses a flat violations key.
Multi-sheet schematics aggregate violations across all sheets.
Test coverage
3 new tests in TestErcJsonParsing:
test_kicad9_sheets_format— 2 violations nested under sheets, verifies count and severity breakdowntest_flat_violations_format— legacy top-level violations key still workstest_multi_sheet_violations_aggregated— 2 sheets with 2+1 violations = 3 total
253/253 pass, ruff + mypy clean.
Verification
Ran the fixed code against your schematic path. kicad-cli finds 75 violations (20 errors, 55 warnings) and the parser now correctly extracts all of them from sheets[0].violations.