I have a nested list as follows:
mylist <- list(
list(
id = 1234,
attributes = list(
list(
typeId = 11,
type = 'Main',
date = '2018-01-01',
attributes= list(
list(
team = 'team1',
values = list(
value1 = 1,
value2 = 999)),
list(
team = 'team2',
values = list(
value1 = 2,
value2 = 888))
)
),
list(
typeId = 12,
type = 'Extra',
date = '2018-01-02',
attributes= list(
list(
team = 'team1',
values = list(
value1 = 3,
value2 = 1234)),
list(
team = 'team2',
values = list(
value1 = 4,
value2 = 9876))
)
)
)
)
)
which I want to convert into a dataframe where each child entry is in a row alongside all its parent entries. So I would end up with a dataframe which looks like
id type_id type date team value1 value2
1 1234 11 Main 2018-08-01 team1 1 999
2 1234 11 Main 2018-08-01 team2 2 888
3 1234 12 Extra 2018-08-02 team1 3 1234
4 1234 12 Extra 2018-08-02 team2 4 9876
I do not always know the names within my list, so would need a generic way of doing this without specifying column names
EDIT
I have an answer to my initial question, but in response to Parfaits comment "If you post original JSON and your R import code a simpler solution maybe available".
My get my original JSON from a url using R code:
httr::GET(
feed_url,
authenticate(username, password)
) %>%
httr::content()
Within the url the JSON would look like:
[{"id":[1234],"attributes":[{"typeId":[11],"type":["Main"],"date":["2018-01-01"],"attributes":[{"team":["team1"],"values":{"value1":[1],"value2":[999]}},{"team":["team2"],"values":{"value1":[2],"value2":[888]}}]},{"typeId":[12],"type":["Extra"],"date":["2018-01-02"],"attributes":[{"team":["team1"],"values":{"value1":[3],"value2":[1234]}},{"team":["team2"],"values":{"value1":[4],"value2":[9876]}}]}]}]