Skip to content

Instantly share code, notes, and snippets.

@sulincix
Last active December 21, 2024 01:42
Show Gist options
  • Save sulincix/a58953e69cca96a612d6f0e8059a2af8 to your computer and use it in GitHub Desktop.
Save sulincix/a58953e69cca96a612d6f0e8059a2af8 to your computer and use it in GitHub Desktop.
json formater in posix shell and just sed command
#!/bin/sh
i=0
sed \
"
s/^ *//g
s/^\t*//g
s/,/,\n/g
s/{/\n&\n/g
s/}/\n&/g
s/\[/&\n/g
s/\]/\n&\n/g
" |while read line ; do
case "$line" in
"{")
i=$(expr $i + 1)
;;
esac
if [ $i -gt 1 ] ; then
j=0
while [ $j -lt $i ] ; do
echo -n " "
j=$(expr $j + 1)
done
fi
case "$line" in
"}")
i=$(expr $i - 1)
;;
esac
echo $line
done | sed "/^$/d"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment