Skip to content

Instantly share code, notes, and snippets.

@nkrabben
Created December 17, 2019 23:29
Show Gist options
  • Save nkrabben/ecf8ff4e377349fffc6e7d0fcf4acb6f to your computer and use it in GitHub Desktop.
Save nkrabben/ecf8ff4e377349fffc6e7d0fcf4acb6f to your computer and use it in GitHub Desktop.
Convert IA JSON to a CSV using standard libraries
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