Skip to content

command-line flag to replace spaces in key names with underscores for JSON output #240

@mmguero

Description

@mmguero

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}"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions