Skip to content

Instantly share code, notes, and snippets.

@ErikBoesen
Created April 16, 2021 11:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ErikBoesen/41cfe3bb4d8838ae386f43c9b85b4b6c to your computer and use it in GitHub Desktop.
Save ErikBoesen/41cfe3bb4d8838ae386f43c9b85b4b6c to your computer and use it in GitHub Desktop.
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