Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Iterate through json response

I’m trying to iterate through a json response, method is get.

this is the json

{
"snapshots" : [ 
{
"snapshot" : "First"},
{
"snapshot" : "Second"}

I would like to know if any of you have an easy way to iterate through this and get the value of "snapshot" key, with python 3.X
thanks in advance

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Here an example

import json

var= """
{
 "snapshots" : [
 {
 "snapshot" : "First"},
 {
 "snapshot" : "Second"}

 ]
 }

 """

data = json.loads(var)

for snapshot in data["snapshots"]:
        print(f'Value :{snapshot["snapshot"]}')

The output that i got :

Value :First
Value :Second
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading