spark: add JSON SHA256 validator with test results

This commit is contained in:
spark committed 2026-10-26 18:23:22 +00:00
1 parent 2d8254dd13
commit 48bdc86156
3 files changed
+79

No files matched your search

@@ -0,0 +1,18 @@
JSON SHA256 Validator Test Results
===================================
Date: 2026-10-26
Tool: json_sha256_validator.py
Test Input Files:
1. test_data.json
2. validator_run.json
Validation Results:
- test_data.json: VALID
SHA256: da0e6981b949cea01bc6b2f027872d54d54f1629ecfb65ba27e9525d320a270e
- validator_run.json: VALID
SHA256: ae961b6113f15a31735d5e1a3efbef5be7db66e312bd3184573cfa1082968c90
Overall Status: PASSED
Exit Code: 0
@@ -0,0 +1,60 @@
#!/usr/bin/env python3
"""Simple JSON validator that generates SHA256 checksums for verification."""
import json
import sys
import hashlib
from pathlib import Path
def validate_json_file(filepath: str) -> tuple[bool, str]:
"""Validate a JSON file and return (is_valid, error_message)."""
try:
with open(filepath, 'r') as f:
json.load(f)
return True, ""
except json.JSONDecodeError as e:
return False, f"Invalid JSON: {e}"
except FileNotFoundError:
return False, f"File not found: {filepath}"
except Exception as e:
return False, f"Error: {e}"
def compute_sha256(filepath: str) -> str:
"""Compute SHA256 hash of a file."""
sha256_hash = hashlib.sha256()
with open(filepath, 'rb') as f:
for byte_block in iter(lambda: f.read(4096), b""):
sha256_hash.update(byte_block)
return sha256_hash.hexdigest()
def main():
if len(sys.argv) < 2:
print("Usage: json_sha256_validator.py <file1.json> [file2.json ...]")
sys.exit(1)
results = []
all_valid = True
for filepath in sys.argv[1:]:
is_valid, error = validate_json_file(filepath)
if is_valid:
checksum = compute_sha256(filepath)
results.append(f"VALID {filepath} SHA256={checksum}")
else:
results.append(f"INVALID {filepath} ERROR={error}")
all_valid = False
for r in results:
print(r)
if all_valid:
sys.exit(0)
else:
sys.exit(1)
if __name__ == "__main__":
main()
+1
View File
@@ -0,0 +1 @@
{"name": "spark_validator_test", "version": "1.0", "valid": true}