-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathjson2csv1.py
More file actions
28 lines (23 loc) · 877 Bytes
/
json2csv1.py
File metadata and controls
28 lines (23 loc) · 877 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
26
27
28
import csv
import json
x="""[
{ "pk": 22, "model": "auth.permission", "fields":
{ "codename": "add_logentry", "name": "Can add log entry", "content_type": 8 }
},
{ "pk": 23, "model": "auth.permission", "fields":
{ "codename": "change_logentry", "name": "Can change log entry", "content_type": 8 }
},
{ "pk": 24, "model": "auth.permission", "fields":
{ "codename": "delete_logentry", "name": "Can delete log entry", "content_type": 8 }
}
]"""
x = json.loads(x)
f = csv.writer(open("test.csv", "wb+"))
# Write CSV Header, If you dont need that, remove this line
f.writerow(["pk", "model", "codename", "name", "content_type"])
for x in x:
f.writerow([x["pk"],
x["model"],
x["fields"]["codename"],
x["fields"]["name"],
x["fields"]["content_type"]])