Some fields in Json output have spaces in the names, e.g., .Event.EventData.Error Description. This introduces some complications when forwarding the resultant JSON in to various other tools (logstash, in my case).
I've worked out a command for jq to replace the spaces in field names with underscore, but it would be convenient to have a command-line flag to do it, producing, for example, .Event.EventData.Error_Description instead.
FWIW for anybody else who stumbles across this and wants to know how I'm doing it with jq:
evtx \
--threads 1 \
--format jsonl \
--separate-json-attributes \
"${FNAME}" 2>/dev/null | jq -c 'def walk(f):
. as $in
| if type == "object" then
reduce keys[] as $key
( {}; . + {($key | gsub(" "; "_")): ($in[$key] | walk(f))} )
elif type == "array" then
map( walk(f) )
else
f
end;
walk(.)' > "${FNAME_JSON}"
Some fields in Json output have spaces in the names, e.g.,
.Event.EventData.Error Description
. This introduces some complications when forwarding the resultant JSON in to various other tools (logstash, in my case).I've worked out a command for
jq
to replace the spaces in field names with underscore, but it would be convenient to have a command-line flag to do it, producing, for example,.Event.EventData.Error_Description
instead.FWIW for anybody else who stumbles across this and wants to know how I'm doing it with
jq
: