I have this JSON:
[ {"alert_timestamp": "2024-10-23T08:49:08Z","odin_timestamp": "2024-10-23T08:50:10Z","alert_url": null,"comments": null,"owner": null,"updated_date": null,"clear_timestamp": "2024-10-23T09:27:39Z","outage_duration_in_minutes": 38.52,"published_on": "DEFAULT","atr_exec_id": null,"atr_status": null }]
And, in the even that some fields, like comments
isn't null, I need to strip out newlines and tabs. If it is null, then keep it null
I have tried the following:
map(.comments? |= (gsub("\r\n"; "") | gsub("\t"; ""))) |map(.alert_message? |= (gsub("\r\n"; "") | gsub("\t"; "")))
Which results in:
jq: error (at 16.json:338): null (null) cannot be matched, as it is not a string
And I have tried the //
alternative operator:
map((.comments // "") |= (gsub("\r\n"; "") | gsub("\t"; ""))) |map((.alert_message // "") |= (gsub("\r\n"; "") | gsub("\t"; "")))
yielding:
jq: error (at 16.json:338): Invalid path expression with result ""
There has to be a simple way to handle this without an if else