#!/bin/sh -e

if [ "$#" -lt 1 ]; then
  echo "Usage: format-json [file]"
  exit 127
fi

for file in "${@-}"; do
  tmpdir=$(mktemp -d)
  cp "${file}" "${tmpdir}/input.json"
  python3 -m json.tool "${tmpdir}/input.json" "${tmpdir}/formatted.json"
  mv "${tmpdir}/formatted.json" "${file}"
done
