Creating nested JSON file using Python
I am working on a code part, where we are expected to reproduce similar nested structure as NoSQL/SQL queries and store them into JSON file along with preserving their relationship. Hence we are expected to export the data from the dataframe to the JSON file, also preserve its dependency and create a JSON file, with nested attributes. Seeking some help to reproduce the results in JSON file as shown below.
Data:
Emp_No | Name | Salary | Effect_From |
1 | Emp1 | 1000 | 01-Jan-2012 |
1 | Emp1 | 700 | 01-Jan-2014 |
2 | Emp2 | 1000 | 5-Jun-2015 |
Resultant JSON:
{
"Records"[
{
"Emp_No":"1",
"Name":"Emp1",
"Salary_Details":[
{
"Salary":"1000",
"Effect_From":"01-Jan-2012"
},
{
"Salary":"700",
"Effect_From":"01-Jan-2014"
}
]
},
{
"Emp_No":"2",
"Name":"Emp2",
"Salary_Details":[
{
"Salary":"1000",
"Effect_From":"5-Jun-2015"
}
]
}
]
}