I'm working on the Adobe Analytics reporting/datawarehouse API, and how to process this data into rows and columns (I'm using python and pandas to solve this). This is all going fine as long as only one dimension is used, but when multiple are queried the idea of breakdowns comes into play.
for example, when I'm using 2 dimensions, the data (JSON format) looks something like this:
{
"report":{
"data":[
{
"name":"June 13,2017",
"breakdown":[
{
"name":"nl",
"breakdown":[
{
"name":"not logged in",
"counts":[
"10",
"12"
]
},
{
"name":"logged in",
"counts":[
"30",
"2"
]
}
]
}, ... etc.
To elaborate, counts represents an array of metrics and every breakdown represents a dimension (the numbers and names are fictional).
What I want to do here is to build up sets of data that I can ultimately link together in rows and columns, so the first row of the example would be ( "June 13,2017","nl","not logged in",10,12).
in the example situation I could already do that with the following code:
for period in dataObj['report']['data']:
for firstbreakdown in period['breakdown']:
for secondbreakdown in firstbreakdown['breakdown']:
print(period['name'], firstbreakdown['name'], secondbreakdown['name'], secondbreakdown['counts'])
Processing the counts here is not a problem as I've found out I can easily do that with pandas. But here comes the tricky part and my actual question: the number of breakdowns in the JSON example is determined by the number of dimensions that are queried upon.
How can I automatically, based on the number of dimensions queried, make enough loops to keep getting all the dimension values and counts in a row?
I would prefer an elegant & always working solution to do this instead of an if else statement.