Improve sorting of json and xml export attributes

This commit is contained in:
JonnyWong16
2020-10-11 16:03:16 -07:00
parent 270e07341a
commit a39c6c1047
2 changed files with 30 additions and 2 deletions

View File

@@ -1650,12 +1650,14 @@ class Export(object):
writer.writerows(csv_data)
elif self.file_format == 'json':
json_data = json.dumps(result, indent=4, ensure_ascii=False, sort_keys=True)
json_data = json.dumps(helpers.sort_obj(result),
indent=4, ensure_ascii=False)
with open(filepath, 'w', encoding='utf-8') as outfile:
outfile.write(json_data)
elif self.file_format == 'xml':
xml_data = helpers.dict_to_xml({self.media_type: result}, root_node='export', indent=4)
xml_data = helpers.dict_to_xml({self.media_type: helpers.sort_obj(result)},
root_node='export', indent=4)
with open(filepath, 'w', encoding='utf-8') as outfile:
outfile.write(xml_data)