Skip to content

Instantly share code, notes, and snippets.

@jcasts
Created March 29, 2012 22:29
Show Gist options
  • Save jcasts/2244392 to your computer and use it in GitHub Desktop.
Save jcasts/2244392 to your computer and use it in GitHub Desktop.
Easy JSON command line parser
#! /bin/bash
# Prerequisite:
# $ gem install kronk
# Usage:
# json '{"foo": "bar"}'
# json example.com/foo.json
# echo '{"foo": "bar"}' | json
# See http://github.com/yaksnrainbows/kronk for more options
args=( "$@" )
first=${args[0]}
fchar=${first:0:1}
if [[ "$fchar" == '{' || "$fchar" == '[' ]]; then
echo "$first" | kronk --parser json ${args[@]:1}
else
kronk --parser json $@
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment