I have an output which is in XML format and I have converted that XML format output to JSON. After converting the data to JSON I need to print only selected output.
api = NaElement("snapmirror-get")
xo = s.invoke_elem(api)
if (xo.results_status() == "failed"):
print ("Error:\n")
print (xo.sprintf())
sys.exit(1)
print ("Received:\n")
print (xo.sprintf())
data = json.loads(json.dumps(xmltodict.parse(xo.sprintf())))
This is the code I'm using to convert an XML file to JSON. The output will save in data variable and I need to print only selected output. Below is the output of data variable.
{'results': {'@status': 'passed', 'attributes': {'snapmirror-info': {'break-failed-count': '0', 'break-successful-count': '0', 'destination-location': 'svm-svm1-vault:volume1', 'destination-volume': 'volume1', 'destination-volume-node': 'svm1cdot1-02', 'destination-vserver': 'svm-svm1-vault', 'destination-vserver-uuid': '545fa72b-e84c-11e6-ae0a-00a098546e58', 'exported-snapshot': 'daily.2019-01-03_0010', 'exported-snapshot-timestamp': '1546454401', 'is-constituent': 'false', 'is-healthy': 'true', 'lag-time': '46182', 'last-transfer-duration': '759', 'last-transfer-end-timestamp': '1546469259', 'last-transfer-from': 'svm-svm1:volume1', 'last-transfer-network-compression-ratio': '1:1', 'last-transfer-size': '5192737823', 'last-transfer-type': 'update', 'max-transfer-rate': '0', 'mirror-state': 'snapmirrored', 'newest-snapshot': 'daily.2019-01-03_0010', 'newest-snapshot-timestamp': '1546454401', 'opmask': '18446744073709551615', 'policy': 'Daily_policy1', 'policy-type': 'vault', 'relationship-control-plane': 'v2', 'relationship-group-type': 'none', 'relationship-id': '4557665a-ebcd-11e6-ae0a-00a098546e58', 'relationship-status': 'idle', 'relationship-type': 'vault', 'resync-failed-count': '0', 'resync-successful-count': '0', 'schedule': Rep_Set_01', 'source-location': ''svm-svm1:volume1', 'source-volume': 'volume1', 'source-vserver': 'svm-scr1', 'source-vserver-uuid': 'acce074e-e14d-11e6-93ae-00a09899b4be', 'total-transfer-bytes': '27879000066', 'total-transfer-time-secs': '2043', 'update-failed-count': '0', 'update-successful-count': '8', 'vserver': 'svm-svm1-vault'}}}}
From the above output I need to print only lag-time
value and source-volume
name output.