I've written an API to organize my daily user data.
The origin format is like
"dau": {
"2017-05-02": 1,
"2017-05-04": 2,
"2017-05-05": 2,
}
"new_user": {
"2017-05-02": 1,
"2017-05-04": 0,
"2017-05-07": 0,
}
It's hard to display in HTML table row by row.
Therefore, I want the format to become this one.
However, I have no idea how to deal with.
info: {
"2017-05-02": {
dau: 1,
new_user: 1
},
"2017-05-04": {
dau: 2,
new_user: 0
},
"2017-05-05": {
dau: 2
},
"2017-05-07": {
new_user: 0
}
}
suppose you have
data
, thenand if you don't want default/0 values then,
Output:
Hope it helps..
Here's an alternative with
each_with_object
. It should work with any number of keys: