-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson_script.py
More file actions
38 lines (28 loc) · 825 Bytes
/
json_script.py
File metadata and controls
38 lines (28 loc) · 825 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
29
30
31
32
33
34
35
36
import json
# This skript is made to parse a file containing a JSON Array of objects like
#this :
# {"header": <string>,
# "description":<string>,
# "id":<string>}
#To a form like the dummy_object where the fields are description, header and
#examples.
with open("glossary_json.json") as json_data:
d = json.load(json_data)
container = list()
for obj in d:
new = dummy_object = {
"model": "stein.glossaryentry",
"pk": "",
"fields": {}
}
new["pk"] = obj["id"]
del obj["id"]
if "list" in obj:
del obj["list"]
new["fields"] = obj
if "examples" in obj:
new["fields"]["examples"] = obj["examples"]
container.append(new)
ret = json.dumps(container)
with open("glossary_16_11_2017.json", "w") as file:
file.write(ret)