I have this dataframe:
df <- data.frame(
item = c("Box 1", "Tape", "Pen"),
length = c(2, 10, NA),
json = c(
'{"size": "size(W x L)", "bubble_height": "bubble height"}',
'{"size": "size(W x L)", "color": "tape color"}',
"{}"
)
)
item length json
1 Box 1 2 {"size": "size(W x L)", "bubble_height": "bubble height"}
2 Tape 10 {"size": "size(W x L)", "color": "tape color"}
3 Pen NA {}
Would like to extract the json data into a column like this:
item length json option_1 option_2
1 Box 1 2 {"size": "size(W x L)", "bubble_height": "bubble height"} size(W x L) bubble height
2 Tape 10 {"size": "size(W x L)", "color": "tape color"} size(W x L) tape color
3 Pen NA {} <NA> <NA>
I haven't found a good solution for this since fromJSON accepts txt rather than a character vector. So I cannot do rowwise %>% to fromJSON.