# A simple example
json <- '{"name": {"first": "Bob", "last": "Jones"}, "age": 32}'
# Using spread_values
json %>%
spread_values(
first.name = jstring(name, first),
last.name = jstring(name, last),
age = jnumber(age)
)
# Another document, this time with a middle name (and no age)
json2 <- '{"name": {"first": "Ann", "middle": "A", "last": "Smith"}}'
# spread_values still gives the same column structure
c(json, json2) %>%
spread_values(
first.name = jstring(name, first),
last.name = jstring(name, last),
age = jnumber(age)
)
# whereas spread_all adds a new column
json %>% spread_all
c(json, json2) %>% spread_all
Run the code above in your browser using DataLab