Skip to content

Commit 0d4013b

Browse files
committed
[#151] Use force_cdata to ensure all text is wrapped in a dict
1 parent 3804108 commit 0d4013b

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

flattentool/json_input.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def __init__(self, json_filename=None, root_json_dict=None, schema_parser=None,
6969
root_json_dict = xmltodict.parse(
7070
xml_file,
7171
force_list=(root_list_path,),
72+
force_cdata=True,
7273
)['iati-activities']
7374
json_filename = None
7475

@@ -125,7 +126,10 @@ def parse_json_dict(self, json_dict, sheet, json_key=None, parent_name='', flatt
125126
if top_level_of_sub_sheet:
126127
# Only add the IDs for the top level of object in an array
127128
for k, v in parent_id_fields.items():
128-
flattened_dict[sheet_key(sheet, k)] = v
129+
if self.xml:
130+
flattened_dict[sheet_key(sheet, k)] = v['#text']
131+
else:
132+
flattened_dict[sheet_key(sheet, k)] = v
129133

130134
if self.root_id and self.root_id in json_dict:
131135
parent_id_fields[sheet_key(sheet, self.root_id)] = json_dict[self.root_id]

0 commit comments

Comments
 (0)