Add first work package for REST API implementation
[anna.git] / example / diameter / launcher / resources / rest_api / helpers / diameterJsonHelper / xml2json.py
1 #!/usr/bin/python3
2 import xmltodict
3 import json
4 import sys
5
6 try:
7   file = sys.argv[1]
8 except:
9   print("Usage: " + sys.argv[0] + " <diameter xml file>")
10   sys.exit(1)
11
12 try:
13   with open(file, 'r') as myfile:
14     xml = myfile.read()
15 except:
16   print("ERROR reading '" + file + "'")
17   sys.exit(1)
18
19 # although default attribute prefix is '@', anyway we will
20 # force the value just in case xmltodict implementation
21 # changes. The anna::core::functions::json2xml helper,
22 # assumes this prefix in order to work properly.
23 my_dict=xmltodict.parse(xml, attr_prefix='@')
24 json_data=json.dumps(my_dict, indent=3, sort_keys=True)
25 print(json_data)