Created
April 16, 2021 11:29
-
-
Save ErikBoesen/41cfe3bb4d8838ae386f43c9b85b4b6c to your computer and use it in GitHub Desktop.
This file contains 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 | |
def clean_one(person: dict): | |
""" | |
Remove empty properties from person record. | |
:param person: single person record. | |
""" | |
return {k: v for k, v in person.items() if v or type(v) == bool} | |
def clean(people): | |
""" | |
Remove empty properties from a list of people. | |
:param person: list of people records. | |
""" | |
return [clean_one(person) for person in people] | |
with open('scraped_data.json', 'r') as f: | |
data = json.load(f) | |
data = clean(data) | |
with open('scraped_data_clean.json', 'w') as f: | |
json.dump(data, f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment