Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mmguero opened this issue Jun 6, 2024 · 0 comments

Comments

@mmguero
Copy link

mmguero commented Jun 6, 2024

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}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant