Skip to content

Instantly share code, notes, and snippets.

@seren
Created May 4, 2016 22:06
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 seren/eb80611aeec2898a0e44e243f80a832b to your computer and use it in GitHub Desktop.
Save seren/eb80611aeec2898a0e44e243f80a832b to your computer and use it in GitHub Desktop.
[{
"name": "wik.is",
"id": 561968,
"address": {
"city": "new york",
"state": "NY"
}
},{
"name": "bob.com",
"id": 50000,
"address": {
"city": "austin",
"state": "TX"
}
}]
# Get the id of bob.com
jq '.[] | select(.name=="bob.com") | .id'
# Get the id and state of bob.com
jq '.[] | select(.name=="bob.com") | {id, state: .address.state}'
--------------------------
{
"Computers": [
{
"Name": "Bob-box",
"Tags": [
{
"Name": "owner",
"Value": "bob"
},
{
"Name": "backup",
"Value": "true"
}
]
},
{
"Name": "Fred-box",
"Tags": [
{
"Name": "owner",
"Value": "fred"
},
{
"Name": "backup",
"Value": "false"
}
]
}
]
}
# Get the computer names that have the backup tag set to true
cat computers.json | jq '.Computers[] | select (.Tags[] | .Name == "backup" and .Value == "true") | .Name'
------------------
# Get the cms instances from EC2
aws ec2 describe-instances | jq '[.Reservations[] | .Instances[] | select( .Tags[] | .Key == "server_type" and .Value == "cms") | {InstanceId, PrivateIpAddress, PublicIpAddress, PublicDnsName}]'
------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment