0

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.

16
  • 1
    do you want same output in dictionary object? Commented Jul 5, 2020 at 5:19
  • Yes, that's what I am trying to achieve. Commented Jul 5, 2020 at 5:27
  • json.loads(response.text) Commented Jul 5, 2020 at 5:34
  • @Sharvin Use this json.loads(response.text) Commented Jul 5, 2020 at 5:40
  • Any help regarding organizing the data will also be great 😁 Commented Jul 5, 2020 at 5:51

1 Answer 1

1

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).
Sign up to request clarification or add additional context in comments.

4 Comments

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.
There is a need for a dictionary that has the key of part number and value of the desired keys from the JSON object.
How do I achieve that? I have added an expected output in my question too.
The response and the expected outputted are not the same the have different keys

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.