Skip to content

Instantly share code, notes, and snippets.

@nilium nilium/jsonkv
Created Dec 20, 2018

Embed
What would you like to do?
Short bash script to create a JSON object from a sequence of key-value arguments
#!/usr/bin/env bash
case "$1" in
-h|--help)
echo 'Usage: jsonkv [-h|--help] [--] KEY VALUE...' 1>&2
exit 2
;;
--)
shift
;;
esac
while [ $# -gt 0 ]; do
jq -n --arg k "$1" --arg v "$2" '{ ($k): (try ($v | fromjson) catch $v) }'
shift
shift
done | jq -s add
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.