by asamarin · 9y ago · 0 comments
jq & jo are the Calvin & Hobbes of the shell: lots of fun together!
A few examples:
- Generate a simple JSON object:
$ jo foo=12 bar=true baz=null
{"foo":12,"bar":true,"baz":"null"}
- Want a nested object? $ jo foo=12 bar=true baz=null thing=$(jo number=57 test=string)
{"foo":12,"bar":true,"baz":"null","thing":{"number":57,"test":"string"}}
- What about arrays? $ jo thing=$(jo number=57 test=string) anarray=$(jo -a 1 2 3 4 5)
{"thing":{"number":57,"test":"string"},"anarray":[1,2,3,4,5]}
- Now let's add some jq magic to sum all the values in the array together: $ jo thing=$(jo number=57 test=string) anarray=$(jo -a 1 2 3 4 5) | jq '.anarray | add'
15
Great stuff :)No comments yet.