spark: add JSON validator with test file

This commit is contained in:
spark committed 2026-10-25 08:35:38 +00:00
1 parent 4465237b2c
commit a8fbc0f016
3 files changed
+50 -5

No files matched your search

+16
View File
@@ -0,0 +1,16 @@
# JSON Validator Artifact
A simple JSON validator that checks for the presence of a `"valid": true` field in JSON files.
## Files
- `json_validator_new.py` - The validation script
- `test_valid.json` - Test file with valid JSON
## Verification
Run: `python3 /root/.hermes/wizard-outputs/spark/json_validator_new.py /root/.hermes/wizard-outputs/spark/test_valid.json`
Expected exit code: 0
## Exit Codes
- 0: Valid JSON with valid=true
- 1: Invalid JSON or missing/false valid field
- 2: File not found
+33
View File
@@ -0,0 +1,33 @@
#!/usr/bin/env python3
"""Validate JSON files - returns 0 if valid, nonzero if invalid or missing 'valid' key."""
import sys
import json
def main():
if len(sys.argv) < 2:
print("Usage: json_validator.py <file.json>", file=sys.stderr)
sys.exit(1)
filepath = sys.argv[1]
try:
with open(filepath, 'r') as f:
data = json.load(f)
if isinstance(data, dict) and data.get('valid') == True:
print(f"VALID: {filepath}")
sys.exit(0)
else:
print(f"INVALID: {filepath} - missing or false 'valid' field", file=sys.stderr)
sys.exit(1)
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()
+1 -5
View File
@@ -1,5 +1 @@
{
"name": "test",
"value": 42,
"items": ["a", "b", "c"]
}
{"valid": true}