Converting API that consist of XML format data into JSON through Azure function python code.
Consider we have one API that consists of XML format data, Based on parameter passing We need to extract particular data from the API. The output format should be in JSON.
Steps:
1) Import XML.etree.ElementTree package to read API.
2) Import urllib.request for opening API URL.
3) Import config to hide the URL
4) Import xmltodict to converting XML to dictionary.
5) Import JSON to convert output format into JSON
Here I am using one API that consists of XML format data.
API Data Format:
Case1:
Without any Transformation:
We can Directly Convert the entire data which was presented in API by flowing python code.
Case 2:
With Transformations:
If we need to extract data based on the parameter the following code will be used.
Here, I am passing the parameter as currency code. in that parameter, I will pass the currency codes like INR, USD, etc. if I pass the parameter value the code needs to give particular country details only.
The following code will be used to perform these actions.
Comments
Post a Comment