Step by step convert exported JSON data from AWS DynamoDB table into CSV, by using jq
.
Export all the data from AWS DynamoDB table at first:
1 | 𝜆 aws --profile production dynamodb scan --table-name tiles > tiles.json |
The exported JSON data looks like:
1 | { |
Extract / transform JSON data:
1 | 𝜆 cat tiles.json | jq '[.Items[] | { id: .id.S, title: .title.S, description: .description.S, status: .status.S, valid_from: .valid_from.S, valid_to: .valid_to.S }]' > tiles-extracted.json |
Convert JSON data into CSV:
1 | 𝜆 cat tiles-extracted.json | jq -r '(.[0] | keys_unsorted) as $keys | $keys, map([.[ $keys[] ]])[] | @csv' > tiles.csv |
References
- How to convert arbitrary simple JSON to CSV using jq, https://stackoverflow.com/questions/32960857/how-to-convert-arbitrary-simple-json-to-csv-using-jq