Created
December 20, 2018 23:57
-
-
Save nilium/54475b4a65da9baa6bbb062105f626a2 to your computer and use it in GitHub Desktop.
Short bash script to create a JSON object from a sequence of key-value arguments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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