#!/usr/bin/env sh
#
# jqjsonl - output JSONL from an array - or object-of-objects with jq

while [ "$#" -gt 0 ]; do
  # shellcheck disable=SC2249
  case "$1" in
    -h)
      printf '%s\n' "${0##*/}: output JSONL from array or object-of-objects with jq"
      exit 0
      ;;
    -x)
      PS4='[${LINENO}]+ '
      set -o xtrace
      ;;
  esac
done
shift "$((OPTIND - 1))"

jq -c '
if type == "array" then .[]
elif type == "object" then to_entries[] | {(.key): (.value)}
end
'
