Skip to main content
deleted 1 character in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

I'm assuming you want to get the logGroups entries that don't have a retentionInDays key at all.

$ jq '.logGroups[] | select( has("retentionInDays") == false )' file.json
{
  "storedBytes": 0,
  "metricFilterCount": 0,
  "creationTime": 1245,
  "logGroupName": "/aws/elasticbeanstalk/nginx",
  "arn": "longarnhere"
}

If you want an array of these (likely, if there may be more than one):

$ jq '[ '.logGroups[]logGroups | map(select( has("retentionInDays") == false ) ]')' file.json
[
  {
    "storedBytes": 0,
    "metricFilterCount": 0,
    "creationTime": 1245,
    "logGroupName": "/aws/elasticbeanstalk/nginx",
    "arn": "longarnhere"
  }
]

You could also use has("retentionInDays") | not in place of has("retentionInDays") == false.

I'm assuming you want to get the logGroups entries that don't have a retentionInDays key at all.

$ jq '.logGroups[] | select( has("retentionInDays") == false )' file.json
{
  "storedBytes": 0,
  "metricFilterCount": 0,
  "creationTime": 1245,
  "logGroupName": "/aws/elasticbeanstalk/nginx",
  "arn": "longarnhere"
}

If you want an array of these (likely, if there may be more than one):

$ jq '[ .logGroups[] | select( has("retentionInDays") == false ) ]' file.json
[
  {
    "storedBytes": 0,
    "metricFilterCount": 0,
    "creationTime": 1245,
    "logGroupName": "/aws/elasticbeanstalk/nginx",
    "arn": "longarnhere"
  }
]

I'm assuming you want to get the logGroups entries that don't have a retentionInDays key at all.

$ jq '.logGroups[] | select( has("retentionInDays") == false )' file.json
{
  "storedBytes": 0,
  "metricFilterCount": 0,
  "creationTime": 1245,
  "logGroupName": "/aws/elasticbeanstalk/nginx",
  "arn": "longarnhere"
}

If you want an array of these (likely, if there may be more than one):

$ jq '.logGroups | map(select( has("retentionInDays") == false ))' file.json
[
  {
    "storedBytes": 0,
    "metricFilterCount": 0,
    "creationTime": 1245,
    "logGroupName": "/aws/elasticbeanstalk/nginx",
    "arn": "longarnhere"
  }
]

You could also use has("retentionInDays") | not in place of has("retentionInDays") == false.

Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

I'm assuming you want to get the logGroups entries that don't have a retentionInDays key at all.

$ jq '.logGroups[] | select( has("retentionInDays") == false )' file.json
{
  "storedBytes": 0,
  "metricFilterCount": 0,
  "creationTime": 1245,
  "logGroupName": "/aws/elasticbeanstalk/nginx",
  "arn": "longarnhere"
}

If you want an array of these (likely, if there may be more than one):

$ jq '[ .logGroups[] | select( has("retentionInDays") == false ) ]' file.json
[
  {
    "storedBytes": 0,
    "metricFilterCount": 0,
    "creationTime": 1245,
    "logGroupName": "/aws/elasticbeanstalk/nginx",
    "arn": "longarnhere"
  }
]