Created
September 2, 2017 03:35
-
-
Save genderquery/261406d91697ed1f547e0a47a5bb52ab 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 os | |
import glob | |
import csv | |
import json | |
directory = 'Street Parking Category' | |
base = 'C:\\Users\\Avery\\Downloads\\' | |
working_path = os.path.join(base, directory) | |
csv_path = os.path.join(base, directory + '.csv') | |
json_paths = glob.glob(os.path.join(working_path, '*.json')) | |
with open(csv_path, 'w', newline='') as csv_file: | |
csv_writer = None | |
for json_path in json_paths: | |
json_root = None | |
with open(json_path, 'r') as json_file: | |
json_root = json.load(json_file) | |
if (csv_writer is None): | |
fields = json_root['fields'] | |
fieldnames = [field['name'] for field in fields] | |
csv_writer = csv.DictWriter(csv_file, fieldnames) | |
csv_writer.writeheader() | |
features = json_root['features'] | |
for feature in features: | |
attributes = feature['attributes'] | |
csv_writer.writerow(attributes) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment