Skip to content

Instantly share code, notes, and snippets.

@itayadler
Last active March 24, 2019 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itayadler/6df7e91d5e36a4c1cc2986720c5bee96 to your computer and use it in GitHub Desktop.
Save itayadler/6df7e91d5e36a4c1cc2986720c5bee96 to your computer and use it in GitHub Desktop.
jq rewrite object example and print the top level object
#!/bin/sh
set -e
result=$(cat $1 | jq --arg examplekey 'examplevalue' '.dependencies |= {"newkey": $examplekey} + .')
echo $result | jq . | cat > $1
#for a given object with key 'dependencies', this will add to the object the key "newkey" with value "examplevalue"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment