Files
troupe-standup/wizard-work/spark/jsonlint.sh
T

29 lines
649 B
Bash
Executable File

#!/bin/bash
# jsonlint.sh - Validate and pretty-print JSON files
# Usage: jsonlint.sh <file.json>
if [ -z "$1" ]; then
echo "Usage: jsonlint.sh <file.json>" >&2
exit 1
fi
if [ ! -f "$1" ]; then
echo "Error: File '$1' not found" >&2
exit 1
fi
# Try to validate and pretty-print JSON using Python
python3 -c "
import sys
import json
try:
with open('$1', 'r') as f:
data = json.load(f)
print(json.dumps(data, indent=2, sort_keys=True))
except json.JSONDecodeError as e:
print(f'Invalid JSON: {e}', file=sys.stderr)
sys.exit(1)
except Exception as e:
print(f'Error: {e}', file=sys.stderr)
sys.exit(1)
"