# NOT RUN {
# turn all components of item into columns with json_unnest_wider()
tibble::tibble(
id = 1:2,
x = c(
'{"name": "Peter", "age": 19}',
'{"age": 37}'
)
) %>%
json_unnest_wider(x)
# sort names and specify proto types
tibble::tibble(
id = 1:2,
x = c(
'{"name": "Peter", "age": 19, "purchase_ids": [1, 2]}',
'{"age": 37, "purchase_ids": []}'
)
) %>%
json_unnest_wider(
x,
ptype = list(
age = integer(),
name = character(),
purchase_id = new_json_array()
),
names_sort = TRUE
)
# }
Run the code above in your browser using DataLab