0

How do I access the world_population key data in the following json data using python ?

{
  "ok": true,
  "body": { "world_population": 7795232630, "total_countries": 235 }
}
Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
  • Does this answer your question? [How can I parse (read) and use JSON in Python?](https://stackoverflow.com/questions/7771011/how-can-i-parse-read-and-use-json-in-python) – Karl Knechtel Apr 01 '23 at 07:55

1 Answers1

0

Assuming you have your json in a string format you can do it like this:

import json

your_json = '{"ok": true,"body": { "world_population": 7795232630,"total_countries": 235 }}'

parsed = json.loads(your_json)
print(parsed["body"]["world_population"])
Marko Borković
  • 1,884
  • 1
  • 7
  • 22