Created
December 17, 2019 23:29
-
-
Save nkrabben/ecf8ff4e377349fffc6e7d0fcf4acb6f to your computer and use it in GitHub Desktop.
Convert IA JSON to a CSV using standard libraries
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
import json | |
import csv | |
with open('Downloads/xfrcollective.json', 'r') as f: | |
data = json.load(f) | |
with open('Downloads/xfrcollective.csv', 'w') as f: | |
header = ['addeddate', 'backup_location', 'collection', 'color', 'contact', 'contributor', 'coverage', 'creator', 'curation', 'date', 'description', 'designer', 'identifier', 'illustrator', 'language', 'licenseurl', 'mediatype', 'ocr', 'ppi', 'publicdate', 'publisher', 'rights', 'runtime', 'scanner', 'sound', 'sponsor', 'subject', 'title', 'updatedate', 'updater', 'uploader', 'year'] | |
writer = csv.writer(f, header) | |
writer.writerow(header) | |
for d in data['collection_items']: | |
writer.writerow([d.get(fieldname, '') for fieldname in header]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment