json data:
{testId: '1' studentId:{'s1':{score: 20} 's2':{score: 80}}}
{testId: '2' studentId:{'s1':{score: 60} 's2':{score: 70}}}
{testId: '3' studentId:{'s5':{score: 40} 's7':{score: 30}}}
...
I would like to use JQ to tell me how many students achieved a score > x, for each test.
Thus for the above input and x = 50, the output:
{testId: '1' numStudents:1}
{testId: '2' numStudents:2}
{testId: '3' numStudents:0}
I am able to generate a list of all students who achieved > 50 on each test with
{testId, studentId: .studentId[]?} | select(.studentId.score>50)
This command creates a list of objects where each object contains testId, studentId and score, where all scores are greater than 50. However I do not know how to recombine these results into the output I want.