I have a json file with a load of AWS CloudWatch logs (generated from a CLI command). I'm trying to use jq to only return values for entries that don't have a 'retentionInDays' field. I have the following which returns everything as I want, but I can't seem to filter out the results that do have retentionInDays.
# Working output (unfiltered)
jq ".logGroups[] | { log_name: .logGroupName, log_arn: .arn, retention_scheme: .retentionInDays }" cwlogs.json
I've tried a couple of things, but either get an error, or it completes and outputs nothing:
# Doesn't return anything
jq '.logGroups[] | { log_name: .logGroupName, log_arn: .arn, retention_scheme: select(.retentionInDays | contains ("null")?) }' cwlogs.json
# Errors with "jq: error (at cwlogs.json:760): number (7) and string ("null") cannot have their containment checked"
jq '.logGroups[] | { log_name: .logGroupName, log_arn: .arn, retention_scheme: select(.retentionInDays | contains ("null")) }' cwlogs.json
# Hangs forever
jq '.logGroups[] | select(.retentionInDays != "null").type'
Update: Testable segment of JSON I'm using
{
"logGroups": [
{
"storedBytes": 0,
"metricFilterCount": 0,
"creationTime": 1234,
"logGroupName": "/aws/elasticbeanstalk/docker",
"retentionInDays": 7,
"arn": "longarnhere"
},
{
"storedBytes": 0,
"metricFilterCount": 0,
"creationTime": 1245,
"logGroupName": "/aws/elasticbeanstalk/nginx",
"arn": "longarnhere"
}
]
}
nullvalue for an existing field? The title and the text in the question are contradictory on this point. Also, by "filter out", do you mean "extract" or "discard"?