I have a small requirement where in I need to list down all customers and their amounts for a given fortnight in a JSON format.Currently, I have a dataframe this way -
FortNight Amount Customer Parameter
Apr-2FN-2018 339632.00 10992 CustomerSales
Apr-2FN-2018 27282.00 10994 CustomerSales
Apr-2FN-2018 26353.00 10995 CustomerSales
May-1FN-2018 24797.00 11000 CustomerSales
May-1FN-2018 21093.00 10990 CustomerSales
May-2FN-2018 45679.0 10992 CustomerSales
May-2FN-2018 45459.0 10995 CustomerSales
May-2FN-2018 35885.0 10994 CustomerSales
Expected JSON-
"CustomerSales" : [
{"FortNight" : "Apr-2FN-2018",
"Details" :[
{"Customer": "10992","Amount" : 339632.00},
{"Customer": "10994","Amount" : 27282.00},
{"Customer": "10995","Amount" : 26353.00}
]
},
{"FortNight" : "May-1FN-2018",
"Details" :[
{"Customer": "11000","Amount" : 24797.00},
{"Customer": "10990","Amount" : 21093.00}
]
},
{"FortNight" : "May-2FN-2018",
"Details" :[
{"Customer": "10992","Amount" : 45679.00},
{"Customer": "10995","Amount" : 45459.00},
{"Customer": "10994","Amount" : 35885.00}
]
}
]
I tried the logic from - Convert dataframe to JSON with 2 level nested array
But I am still stuck at another level more.
I tried other ways too, but in vain. Any help is welcome. Thanks in advance!!...