#!/usr/bin/env bash

# In place pretty-print all files in directory passed in
# requires jq

command -v jq >/dev/null 2>&1 || { echo >&2 "I require jq but it's not installed. Get it at https://stedolan.github.io/jq/. Aborting."; exit 1; } 

if [[ -d $1 ]]; then
    for f in $(find $1 -name '*.json');
        do echo "Pretty printing $f ..."
        jq . "$f" > .tmp;
        mv .tmp $f;
    done
elif [[ -f $1 ]]; then
    jq . "$1" > .tmp;
    mv .tmp $1;
else
    echo "$1 is not a valid path to a folder/file"
    exit 1
fi
