Re:Jq: A lightweight and flexible command-line JSON processor
by mathieuruellan on Sunday June 15, 2014 @12:44PM
(#7895616)
I'm using this tool with curl in scripts calling AWS api. Looking for an id of an object (security group, autoscaling group etc.) with its name and referencing it afterward in another command.
[ Parent
| on HN ]
Re:Jq: A lightweight and flexible command-line JSON processor
by gatehouse on Sunday June 15, 2014 @07:52PM
(#7896768)
I've been using it for the exact same thing. One difficulty that I had was that you need to use the raw option, "jq -r" for string output without quotes, but I was looking at the query language documentation and not finding it.
EDIT: here is one I used. Given VOLUME_ID, gets the most recent snapshot-id.
SNAPSHOT_ID=$(\
aws ec2 describe-snapshots --owner-ids xxxxxxxxxxxx --output json |
jq -r "
.Snapshots | sort_by(.StartTime) | reverse[] |
select(.VolumeId==\"$VOLUME_ID\" and .State==\"completed\") |
.SnapshotId
")
EDIT2: now that I'm looking at it, I think that I expected it to work with multiple snapshots but I'm not sure that I tested it.
Re:Jq: A lightweight and flexible command-line JSON processor
by pavel_lishin on Sunday June 15, 2014 @01:03PM
(#7895660)
Hey, me too! It's pretty awesome, although the documentation/examples aren't as great as they could be - it took me some time to figure out how to properly parse arrays, and I'm still not sure how to actually do what I want to do (I want to convert an array of two instance objects into an array with just two instance IDs.
Re:Jq: A lightweight and flexible command-line JSON processor
by mh- on Sunday June 15, 2014 @01:11PM
(#7895690)
% aws ec2 describe-instances --instance-ids '["i-3026a249","i-28739551"]' \
| jq '[.Reservations[].Instances[].InstanceId]'
[
"i-28739551",
"i-3026a249"
]
Re:Jq: A lightweight and flexible command-line JSON processor
by pavel_lishin on Saturday June 21, 2014 @09:55AM
(#7924968)
Thanks!
Re:Jq: A lightweight and flexible command-line JSON processor
by mentat on Monday June 16, 2014 @01:38AM
(#7897561)
I've been using this to transform the output of ElasticBeanstalk environment queries into things I can feed into environment updates since moving between versions is a PITA. Should post that code sometime...