0

How to read First object of nested Json in python?

avatar
Oct. 27, 2020
Hello,

I have a Nested JSON

"response":[
{
"country":"China",
"cases":{
"new":"+31",
"active":2466,
"critical":633,
"recovered":75700,
"total":81470
},
"deaths":{
"new":"+4",
"total":3304
},
"day":"2020-03-30",
"time":"2020-03-30T13:15:10+00:00"
},
{
"country":"Italy",
"cases":{
"new":"+5217",
"active":73880,
"critical":3906,
"recovered":13030,
"total":97689
},
"deaths":{
"new":"+756",
"total":10779
},
"day":"2020-03-30",
"time":"2020-03-30T13:15:09+00:00"
},
{
"country":"Spain",
"cases":{
"new":"+5085",
"active":61075,
"critical":5231,
"recovered":16780,
"total":85195
},
"deaths":{
"new":"+537",
"total":7340
},
"day":"2020-03-30",
"time":"2020-03-30T13:15:09+00:00"
},...........................



Now I want to get the first JSON object from this JSON

The output should be like:
{
"country":"China",
"cases":{
"new":"+31",
"active":2466,
"critical":633,
"recovered":75700,
"total":81470
},
"deaths":{
"new":"+4",
"total":3304
},
"day":"2020-03-30",
"time":"2020-03-30T13:15:10+00:00"
}

Which is First JSON Object.

Can anyone help? Thanks in advance.
avatar
2020-03-30

First load Json to dictionary

import json

data = "Some JSON"
data = json.loads(data)

now if you want the first Object just use

print(data[0])



Please Login to Comment