Skip to content

Commit f2b7d33

Browse files
committed
tools: add JSON syntax validator
1 parent 6c41ce7 commit f2b7d33

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

tools/validate_json_syntax.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env python3
2+
"""Validate JSON syntax for repository schemas and examples."""
3+
from __future__ import annotations
4+
5+
import json
6+
from pathlib import Path
7+
import sys
8+
9+
ROOT = Path(__file__).resolve().parents[1]
10+
11+
12+
def main() -> int:
13+
failed = False
14+
for root_name in ("schemas", "examples"):
15+
root = ROOT / root_name
16+
if not root.exists():
17+
continue
18+
for path in sorted(root.rglob("*.json")):
19+
try:
20+
json.loads(path.read_text(encoding="utf-8"))
21+
except Exception as exc: # noqa: BLE001 - syntax validator should report any parse/read failure.
22+
rel = path.relative_to(ROOT)
23+
print(f"{rel}: invalid JSON: {exc}", file=sys.stderr)
24+
failed = True
25+
if failed:
26+
return 1
27+
print("JSON syntax validated.")
28+
return 0
29+
30+
31+
if __name__ == "__main__":
32+
raise SystemExit(main())

0 commit comments

Comments
 (0)