I have managed to obtain JSON data from API and I am trying to store it in a Python dictionary. I have followed a few tutorials and other stack overflow guides but does not seem to help.
1 Answer
If your API response return JSON object you can try
response.json()
and you will get a dictionary of a JSON object returned by the API.
Elsewhere you if the response.text is returning a JOSN object as string you can use the json package to load the string as a dictionary by json.loads() method as
json.loads(response.text).
4 Comments
Sharvin
It works, thank you. What about sorting the output into categories. For example, the version and title to be categorized as part 1 while file_name, app_name and app_type to be categorized as part 2. In order to make the output more readable and organized as it is just a long line of data right now.
Leo Arad
There is a need for a dictionary that has the key of part number and value of the desired keys from the JSON object.
Sharvin
How do I achieve that? I have added an expected output in my question too.
Leo Arad
The response and the expected outputted are not the same the have different keys
json.loads(response.text)