diff --git a/wizard-work/spark/json_syntax_checker.py b/wizard-work/spark/json_syntax_checker.py new file mode 100644 index 0000000..a54912d --- /dev/null +++ b/wizard-work/spark/json_syntax_checker.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python3 +""" +json_syntax_checker.py - Minimal JSON syntax validator. + +Verifies JSON files are syntactically correct. +Exit 0 = valid JSON, Exit 1 = invalid JSON +""" + +import json +import sys +from pathlib import Path + + +def check_json_syntax(file_path: str) -> tuple[bool, str]: + """Check if file contains valid JSON. + + Returns: (is_valid, message) + """ + path = Path(file_path) + + if not path.exists(): + return False, f"File not found: {file_path}" + + try: + content = path.read_text().strip() + + if not content: + return False, "Empty file" + + json.loads(content) + return True, "Valid JSON" + + except json.JSONDecodeError as e: + return False, f"JSON error at line {e.lineno}, col {e.colno}: {e.msg}" + except Exception as e: + return False, f"Error: {e}" + + +def main(): + if len(sys.argv) < 2: + print("Usage: json_syntax_checker.py ") + sys.exit(1) + + file_path = sys.argv[1] + is_valid, message = check_json_syntax(file_path) + + print(f"{message}") + sys.exit(0 if is_valid else 1) + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/wizard-work/spark/ts_invalid_demo.json b/wizard-work/spark/ts_invalid_demo.json new file mode 100644 index 0000000..84ed132 --- /dev/null +++ b/wizard-work/spark/ts_invalid_demo.json @@ -0,0 +1 @@ +{"name": "broken", "missing_end": true diff --git a/wizard-work/spark/ts_valid_demo.json b/wizard-work/spark/ts_valid_demo.json new file mode 100644 index 0000000..ebfdc29 --- /dev/null +++ b/wizard-work/spark/ts_valid_demo.json @@ -0,0 +1 @@ +{"name": "spark_test", "active": true, "count": 123} \ No newline at end of file