Here is an example of one row of my data frame:
test <- structure(list(index = 1,
id = 100,
creation_date = "2020-11-11 11:38:00",
json_data = "{'alldata': {'values': {'set': {'min': 60, 'max': 190}, 'value': [[112, 111, 89, 78, 178, 90, 80, 56, 80, 95, 120, 140, 160, 156, 100, 77, 90, 89, 100, 112, 111, 89, 78, 178, 90, 80]], 'optimal': {'min': 40, 'max': 190}, 'feature': 'postprandial after 3pm', 'type': {'timerange': 'Yes 3PM-7PM', 'hrs': '4Hr'}}, 'name': 'insight.A'}}"
))
You can see the data is quite complex because there are a ton of numbers in the "values" list within the json_data. I would like to extract all of this information into a data frame while keeping the non-jason_data columns as well.
Ideal output:
df <- data.frame(index = rep(1, each = 26),
id = rep(100, each = 26),
creation_date = rep("2020-11-11 11:38:00", each = 26),
values_set_min = rep(60, each = 26),
values_set_max = rep(190, each = 26),
value = c(112, 111, 89, 78, 178, 90, 80, 56, 80, 95, 120, 140, 160, 156, 100, 77, 90, 89, 100, 112, 111, 89, 78, 178, 90, 80),
optimal_min = rep(40, each = 26),
optimal_max = rep(190, each = 26),
feature = rep("Postprandial after 3PM", each = 26),
type_timerange = rep("Yes 3PM-7PM", each = 26),
type_hrs = rep("4HR", each = 26),
name = rep("insight.A", each = 26)
)
head(df)
index id creation_date values_set_min values_set_max value optimal_min optimal_max feature type_timerange type_hrs name
1 1 100 2020-11-11 11:38:00 60 190 112 40 190 Postprandial after 3PM Yes 3PM-7PM 4HR insight.A
2 1 100 2020-11-11 11:38:00 60 190 111 40 190 Postprandial after 3PM Yes 3PM-7PM 4HR insight.A
3 1 100 2020-11-11 11:38:00 60 190 89 40 190 Postprandial after 3PM Yes 3PM-7PM 4HR insight.A
4 1 100 2020-11-11 11:38:00 60 190 78 40 190 Postprandial after 3PM Yes 3PM-7PM 4HR insight.A
5 1 100 2020-11-11 11:38:00 60 190 178 40 190 Postprandial after 3PM Yes 3PM-7PM 4HR insight.A
6 1 100 2020-11-11 11:38:00 60 190 90 40 190 Postprandial after 3PM Yes 3PM-7PM 4HR insight.A
I have tried jsonlite etc but they always lose the non-JSON columns such as creation_date, which I need. Any help would be much appreciated. Thanks in advance.