forked from ClementCloud/pythonUtilityScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjsonParse.py
More file actions
25 lines (18 loc) · 783 Bytes
/
jsonParse.py
File metadata and controls
25 lines (18 loc) · 783 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Drop your JSON file(s) into the current directory (Use https://elmah.io/tools/json-formatter/ to validate your file)
import json
# Opens the JSON file as readable file and sets the variable 'f' to it
## Loads the contents of the json and sets it to 'data'
with open('INSERT .JSON FILE HERE', 'r') as f:
data = json.load(f)
# Checks the JSON group
## Prints the selected subgroups
for users in data['INSERT MAIN GROUP NAME IN YOUR JSON FILE']:
print(users['SUBGROUP 1'], users['SUBGROUP 2'])
# To insert into a .csv file use this...
import csv
with open('newContent.csv', 'w') as x:
fieldName = data['users'][0].keys()
writer = csv.DictWriter(x,fieldnames=fieldName)
writer.writeheader()
for users in data['users']:
writer.writerow(users)