Created
June 7, 2019 21:03
-
-
Save kyounger/ae52dbee1614f39067ef0ec593d41818 to your computer and use it in GitHub Desktop.
Convert xml from ebscohost to csv using xml2json and jq
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# tools required: | |
# npm install -g xml2json-cli | |
# brew install jq | |
# This command will flatten the resulting array of objects so that the headers are just the json path to the key joined with dots. | |
xml2json file.xml | jq '[.records.rec[] | . as $in | reduce leaf_paths as $path ({}; . + { ($path | map(tostring) | join(".")): $in | getpath($path) })]' | jq -r '(map(keys) | add | unique) as $cols | map(. as $row | $cols | map($row[.])) as $rows | $cols, $rows[] | @csv' > test2.csv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment