spark: json_check.py - validate JSON files from CLI

This commit is contained in:
spark committed 2026-10-25 08:24:18 +00:00
1 parent 5ead88ce0d
commit 9a9c7e899d
1 file changed
+26
+26
View File
@@ -0,0 +1,26 @@
#!/usr/bin/env python3
"""json_check.py - Validate JSON files from command line."""
import sys
import json
def main():
if len(sys.argv) < 2:
print("Usage: json_check.py <file.json>", file=sys.stderr)
sys.exit(1)
filepath = sys.argv[1]
try:
with open(filepath, 'r') as f:
json.load(f)
print(f"VALID: {filepath}")
sys.exit(0)
except json.JSONDecodeError as e:
print(f"INVALID: {filepath} - {e}", file=sys.stderr)
sys.exit(1)
except FileNotFoundError:
print(f"NOT FOUND: {filepath}", file=sys.stderr)
sys.exit(2)
if __name__ == "__main__":
main()