Convert tabular json data to d3 hierarchal data for pack chart

I have a small dataset in JSON file which I want to convert into hierarchal data format to create a circular pack chart.
This is my dataset:

{
"Marks": [
{"student": "Maria", "AI": 95, "DB": 77, "CG": 31, "ITP": 97, "LIT": 45},
{"student": "Sam", "AI": 85, "DB": 37, "CG": 39, "ITP": 45, "LIT": 55}
]
}

This is the output I am looking for:

{
"name": "Marks",
 "children": [
  { "name": "Maria",
 "children": [
  { "name": "AI" , "marks" : 95},
  { "name": "DB" , "marks" : 77},
  { "name": "CG" , "marks" : 35},
  { "name": "ITP" , "marks" : 97},
  { "name": "LIT" , "marks" : 45},
]
},
{ "name": "Sam",
 "children": [
  { "name": "AI" , "marks" : 85},
  { "name": "DB" , "marks" : 37},
  { "name": "CG" , "marks" : 39},
  { "name": "ITP" , "marks" : 45},
  { "name": "LIT" , "marks" : 55},
]
}
]
}


Any idea how I can proceed with this?