File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 ())
You can’t perform that action at this time.
0 commit comments