#!/bin/sh -e
#
# json-format - format json as bat pager with python json.tool

while read -r line; do
  echo "${line}" | bat --show-all
  line="$(echo "${line%
}" | sed "s|.*\[0m\(.*\)|\1|")"
  echo "${line}" | bat --show-all
  command expr length "${line}" \> 2 \
    && echo "${line%,}" | python3 -m json.tool --no-ensure-ascii --sort-keys
done
