26 lines
663 B
Python
26 lines
663 B
Python
#!/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() |