25 lines
490 B
Bash
Executable File
25 lines
490 B
Bash
Executable File
#!/bin/bash
|
|
# Simple JSON validator using jq
|
|
# Returns 0 if valid JSON, 1 if invalid
|
|
|
|
validate_json() {
|
|
local file="$1"
|
|
if [[ ! -f "$file" ]]; then
|
|
echo "Error: File '$file' not found" >&2
|
|
return 1
|
|
fi
|
|
if jq empty "$file" 2>/dev/null; then
|
|
echo "Valid JSON: $file"
|
|
return 0
|
|
else
|
|
echo "Invalid JSON: $file" >&2
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
if [[ $# -eq 0 ]]; then
|
|
echo "Usage: $0 <json-file>" >&2
|
|
exit 1
|
|
fi
|
|
|
|
validate_json "$1" |