In JSON data file, I'd like to obtain the first elements in the object list. So, John, Sam, and James in this case.
I can get first element like this below, but how do I loop through the first objects in that list without specifically replacing below values like 0,1,2?
data[0]["name"][0]
data[1]["name"][0]
data[2]["name"][0]
data[3]["name"][0]
...
code
with open('data.json') as f:
data = json.load(f)
##prints list
print data[0]["name"]
##print first element in that list
print data[0]["name"][0]
json
[{
"name":[ "John", "Sam", "Rick"]
},
{
"name":[ "Sam", "Paul", "Like"]
},
{
"name":[ "James", "Saul", "Jack"]
}
]