I am trying to parse the following student grade report JSON using Python
{
"report":[
{
"enrollment": "rit2011001",
"name": "Julia",
"subject":[
{
"code": "DSA",
"grade": "A"
}
]
},
{
"enrollment": "rit2011020",
"name": "Samantha",
"subject":[
{
"code": "COM",
"grade": "B"
},
{
"code": "DSA",
"grade": "A"
}
]
}
]
}
Such that the report should be ordered ascending first by code, then by grade and then by enrollment. Here is how the output should be
COM B rit2011020 Samantha
DSA A rit2011001 Julia
DSA A rit2011020 Samantha
Here is my incomplete piece of code that I need help with:
import json
data='''{
"report":[
{
"enrollment": "rit2011001",
"name": "Julia",
"subject":[
{
"code": "DSA",
"grade": "A"
}
]
},
{
"enrollment": "rit2011020",
"name": "Samantha",
"subject":[
{
"code": "COM",
"grade": "B"
},
{
"code": "DSA",
"grade": "A"
}
]
}
]
}'''
print data #for debug
parsed_json = json.loads(data)
print parsed_json #for debug
for key,value in sorted(parsed_json.items()):
print key,value
I don't know how to apply successive filtering to achieve the result.