I often get sent HAR files (which are JSON) sent to me that look like this:
{
"log": {
"entries" : [
{
"request" : {
"url" : "test.css"
}
},
{
"request" : {
"url" : "test.ok"
}
},
{
"request" : {
"url" : "test.font"
}
},
{
"request" : {
"url" : "ok"
}
}
]
}
}
I don't care about requests that contain URLs for fonts, CSS, or JavaScript. So, I'd like to remove these requests using jq
. Given the answer from @iain-samuel-mclean-elder about filtering and maintaining the JSON structure of the input, I would expect something like this to work:
jq '[ .[] | select(.log.entries[].request.url | test("\\.(js|css|font)") | not) ]' < MyGoodHarFile.json
This, however, produces the error:
jq: error (at <stdin>:25): Cannot iterate over null (null)
What am I doing wrong? How can I create a valid HAR file excluding requests for these certain matching URLs using jq
?