'Whats the simple way to get the information from nested JSON
I've the sample JSON nested data and if I need to print out the training that each instructor teaches then how do I do that? Is there another way without using json.load()
{
"unit":{
"title":"training jumping",
"raw_title":"{} training",
"item_type":"training",
"items":[
{
"_class":"training",
"training_id":101101,
"title":"the trainig for jumping 202",
"instructor_details":[
{
"image_100x100":"https://img-c.udemycdn.com/user/100x100/4466306_6fd8_3.jpg",
"instructor_id":212212,
"initials":"CS",
"display_name":"Steve Mexican",
"name":"Steve",
"_class":"user",
"title":"Steve Mexica"
}
],
},
{
"_class":"training",
"training_id":121121,
"title":"the trainig for jumping 101",
"instructor_details":[
{
"instructor_id":151151
"image_100x100":"https://img-c.udemycdn.com/user/100x100/4466306_6fd8_3.jpg",
"_class":"user"
"name":"Colt",
"initials":"CS",
"display_name":"Colt Steele",
"title":"Colt Steele"
}
],
},
and more..................... data
}
I've tried:
with open(sample.txt) as sample_file:
training_id = re.findall(r'_class":".+?"."training_id:(\d+)', sample_file) # Creates a list with all the id
instructor_id = re.findall(r'"instructor_details".+?"instructor_id":(\d+)', sample_file) # Creates a list with all the id
# don't understand here how I can match instructor_id with training_id
Output looks like:
instructor_id >> training_id1 + training_id2.........all the training that this instructor teaches
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
