-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathjson_dumps.py
41 lines (38 loc) · 941 Bytes
/
json_dumps.py
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
37
38
39
40
41
import json
JSON_FIELDS = [
"reporting-org",
"title",
"description",
"participating-org",
"other-identifier",
"activity-date",
"contact-info",
"recipient-country",
"recipient-region",
"location",
"sector",
"tag",
"country-budget-items",
"humanitarian-scope",
"policy-marker",
"default-aid-type",
"budget",
"planned-disbursement",
"transaction",
"document-link",
"related-activity",
"legacy-data",
"conditions",
"result",
"crs-add",
"fss",
]
def add_json_dumps(activity):
for field in JSON_FIELDS:
if field in activity:
if isinstance(activity[field], list):
activity[f'json.{field}'] = []
for item in activity[field]:
activity[f'json.{field}'].append(json.dumps(item))
else:
activity[f'json.{field}'] = json.dumps(activity[field])