28 lines
869 B
Python
28 lines
869 B
Python
#!/usr/bin/env python3
|
|
# Debug test
|
|
import json
|
|
from pathlib import Path
|
|
|
|
def normalize_json(data):
|
|
"""Recursively normalize JSON: sort dict keys, convert lists."""
|
|
if isinstance(data, dict):
|
|
return {k: normalize_json(data[k]) for k in sorted(data.keys())}
|
|
elif isinstance(data, list):
|
|
return [normalize_json(item) for item in data]
|
|
else:
|
|
return data
|
|
|
|
# Test with sample_valid.json
|
|
data1 = json.loads(Path('/root/.hermes/wizard-outputs/spark/sample_valid.json').read_text())
|
|
print('Data1:', data1)
|
|
norm1 = normalize_json(data1)
|
|
print('Norm1:', norm1)
|
|
|
|
# Test with sample_invalid.json
|
|
try:
|
|
data2 = json.loads(Path('/root/.hermes/wizard-outputs/spark/sample_invalid.json').read_text())
|
|
print('Data2:', data2)
|
|
except json.JSONDecodeError as e:
|
|
print('JSON error (expected):', e)
|
|
|
|
print('normalize_json works correctly!') |