I receive input from one the API in the following format:
"annual": {
"Revenue": [
{
"date": "2020-06-30",
"value": "12820.000000"
},
{
"date": "2019-06-30",
"value": "9965.000000"
},
{
"date": "2018-06-30",
"value": "6887.000000"
},
{
"date": "2017-06-30",
"value": "8447.000000"
},
{
"date": "2016-06-30",
"value": "7083.000000"
},
{
"date": "2015-06-30",
"value": "8574.000000"
}
],
"Total Revenue": [
{
"date": "2020-06-30",
"value": "12820.000000"
},
{
"date": "2019-06-30",
"value": "9965.000000"
},
{
"date": "2018-06-30",
"value": "6887.000000"
},
{
"date": "2017-06-30",
"value": "8447.000000"
},
{
"date": "2016-06-30",
"value": "7083.000000"
},
{
"date": "2015-06-30",
"value": "8574.000000"
}
],
"Cost of Revenue, Total": [
{
"date": "2020-06-30",
"value": "5742.000000"
},
{
"date": "2019-06-30",
"value": "5115.000000"
},
{
"date": "2018-06-30",
"value": "4930.000000"
},
{
"date": "2017-06-30",
"value": "4888.000000"
},
{
"date": "2016-06-30",
"value": "5064.000000"
},
{
"date": "2015-06-30",
"value": "7427.000000"
}
],
"Gross Profit": [
{
"date": "2020-06-30",
"value": "7078.000000"
},
{
"date": "2019-06-30",
"value": "4850.000000"
},
{
"date": "2018-06-30",
"value": "1957.000000"
},
{
"date": "2017-06-30",
"value": "3559.000000"
},
{
"date": "2016-06-30",
"value": "2019.000000"
},
{
"date": "2015-06-30",
"value": "1147.000000"
}
],
"Selling/General/Admin. Expenses, Total": [
{
"date": "2020-06-30",
"value": "114.000000"
},
{
"date": "2019-06-30",
"value": "95.000000"
},
{
"date": "2018-06-30",
"value": "70.000000"
},
{
"date": "2017-06-30",
"value": "56.000000"
},
{
"date": "2016-06-30",
"value": "52.000000"
},
{
"date": "2015-06-30",
"value": "94.000000"
}
],
"Research & Development": [
{
"date": "2020-06-30",
"value": "63.000000"
},
{
"date": "2019-06-30",
"value": "29.000000"
},
{
"date": "2018-06-30",
"value": "32.000000"
},
{
"date": "2017-06-30",
"value": "51.000000"
},
{
"date": "2016-06-30",
"value": "104.000000"
},
{
"date": "2015-06-30",
"value": "52.000000"
}
],
"Depreciation/Amortization": [
{
"date": "2020-06-30",
"value": "17.000000"
},
{
"date": "2019-06-30",
"value": "12.000000"
},
{
"date": "2018-06-30",
"value": "12.000000"
},
{
"date": "2017-06-30",
"value": "16.000000"
},
{
"date": "2016-06-30",
"value": "21.000000"
},
{
"date": "2015-06-30",
"value": "29.000000"
}
]
}
}
I am trying to restructure the json object so that it looks something like this:
{ "annual": {
"2020-06-30": {
"Revenue":"12820.000000",
"Total Revenue":"12820.000000",
"Cost of Revenue, Total":"5742.000000",
"Gross Profit":"7078.000000",
"Selling/General/Admin. Expenses, Total":"114.000000",
"Research & Development":"63.000000",
"Depreciation/Amortization":"17.000000"
},
"2019-06-30": {...},
"2018-06-30": {...},
"2017-06-30": {...},
"2016-06-30": {...},
"2015-06-30": {...}
}
}
I am relatively new to using JSON with python and I am wondering if there is an efficient way to achieve this?
I have tried converting to a dataframe but I end up with a dataframe that has dictionary objects which needs to be parsed within multiple loops.
Any help or pointers would be greatly appreciated!!