Extract fields from JSON with jq
Bash
#!/usr/bin/env bash
# Extract and filter JSON records with jq.
set -euo pipefail
json_file="${1:?usage: $0 FILE.json}"
command -v jq >/dev/null || { printf 'jq is required\n' >&2; exit 1; }
if [[ ! -s $json_file ]]; then
printf 'missing or empty: %s\n' "$json_file" >&2
exit 1
fi
# Reject malformed JSON before printing anything.
jq -e . -- "$json_file" >/dev/null
# One line per enabled item, most recently updated first.
jq -r '
.items
| map(select(.enabled == true))
| sort_by(.updated_at)
| reverse
| .[]
| "\(.name) [\(.status)]"
' -- "$json_file"
printf 'total records: %s\n' "$(jq '.items | length' -- "$json_file")"