Skip to main content
added 335 characters in body
Source Link
Kusalananda
  • 356.2k
  • 42
  • 737
  • 1.1k

Your query using a particular private IP address:

jq '.DevOps."us-east-1" | map_values(select( .PrivateIpAddress == "10.250.128.77" ))' file

Parametrised to take the query IP address from the command line arguments:

jq --arg addr 10.250.128.77 \
    '.DevOps."us-east-1" | map_values(select( .PrivateIpAddress == $addr ))' file

Your query using a particular Key tag's Value:

jq '.DevOps."us-east-1" | map_values(select( IN(.Tags[]; {Key: "Name", Value: "Network-Test-Host"}) ))' file

Parametrised to take the Key and the Value from the command line arguments:

jq --arg Key Name --arg Value Network-Test-Host \
    '.DevOps."us-east-1" | map_values(select( IN(.Tags[]; $ARGS.named) ))' file

These commands would generate a JSON document with a single object containing the keys+values from your input document's .DevOps."us-east-1" section that matches the queries.

Common for each command is that they apply a select() statement to the values of the .DevOps."us-east-1" section. The boolean expression will be different depending on what subsection you want to test with the query. The sections where the boolean expression evaluates to true will be kept while all other bits are removed.

Your query using a particular private IP address:

jq '.DevOps."us-east-1" | map_values(select( .PrivateIpAddress == "10.250.128.77" ))' file

Parametrised to take the query IP address from the command line arguments:

jq --arg addr 10.250.128.77 \
    '.DevOps."us-east-1" | map_values(select( .PrivateIpAddress == $addr ))' file

Your query using a particular Key tag's Value:

jq '.DevOps."us-east-1" | map_values(select( IN(.Tags[]; {Key: "Name", Value: "Network-Test-Host"}) ))' file

Parametrised to take the Key and the Value from the command line arguments:

jq --arg Key Name --arg Value Network-Test-Host \
    '.DevOps."us-east-1" | map_values(select( IN(.Tags[]; $ARGS.named) ))' file

These commands would generate a JSON document with a single object containing the keys+values from your input document's .DevOps."us-east-1" section that matches the queries.

Your query using a particular private IP address:

jq '.DevOps."us-east-1" | map_values(select( .PrivateIpAddress == "10.250.128.77" ))' file

Parametrised to take the query IP address from the command line arguments:

jq --arg addr 10.250.128.77 \
    '.DevOps."us-east-1" | map_values(select( .PrivateIpAddress == $addr ))' file

Your query using a particular Key tag's Value:

jq '.DevOps."us-east-1" | map_values(select( IN(.Tags[]; {Key: "Name", Value: "Network-Test-Host"}) ))' file

Parametrised to take the Key and the Value from the command line arguments:

jq --arg Key Name --arg Value Network-Test-Host \
    '.DevOps."us-east-1" | map_values(select( IN(.Tags[]; $ARGS.named) ))' file

These commands would generate a JSON document with a single object containing the keys+values from your input document's .DevOps."us-east-1" section that matches the queries.

Common for each command is that they apply a select() statement to the values of the .DevOps."us-east-1" section. The boolean expression will be different depending on what subsection you want to test with the query. The sections where the boolean expression evaluates to true will be kept while all other bits are removed.

Source Link
Kusalananda
  • 356.2k
  • 42
  • 737
  • 1.1k

Your query using a particular private IP address:

jq '.DevOps."us-east-1" | map_values(select( .PrivateIpAddress == "10.250.128.77" ))' file

Parametrised to take the query IP address from the command line arguments:

jq --arg addr 10.250.128.77 \
    '.DevOps."us-east-1" | map_values(select( .PrivateIpAddress == $addr ))' file

Your query using a particular Key tag's Value:

jq '.DevOps."us-east-1" | map_values(select( IN(.Tags[]; {Key: "Name", Value: "Network-Test-Host"}) ))' file

Parametrised to take the Key and the Value from the command line arguments:

jq --arg Key Name --arg Value Network-Test-Host \
    '.DevOps."us-east-1" | map_values(select( IN(.Tags[]; $ARGS.named) ))' file

These commands would generate a JSON document with a single object containing the keys+values from your input document's .DevOps."us-east-1" section that matches the queries.