I have a directory of 143 JSON files (~30 MB), which I would like to combine and convert to a flat data frame. (This might be related to this question, but I couldn't get that solution to work. See bottom for results.)
I'm able to parse a single element just fine, so I think my stumbling block is captured by the reprex below:
chr <- "[{\"sometext_lets_pretend_its_JSON\":999}]"
my_list <- list(chr, chr, chr, chr, chr, chr)
library(purrr)
my_list %>%
map(~ fromJSON(.x))
#[[1]]
# sometext_lets_pretend_its_JSON
#1 999
#
#[[2]]
# sometext_lets_pretend_its_JSON
#1 999
#
#[[3]]
# sometext_lets_pretend_its_JSON
#1 999
#
#[[4]]
# sometext_lets_pretend_its_JSON
#1 999
#
#[[5]]
# sometext_lets_pretend_its_JSON
#1 999
#
#[[6]]
# sometext_lets_pretend_its_JSON
#1 999
I'm trying to get a data frame that shows all the rows from the source files, but the flattened version only shows the first element. What am I doing wrong here?
my_list %>%
map(~ fromJSON(.x)) %>%
flatten_dfr()
## A tibble: 1 x 1
# sometext_lets_pretend_its_JSON
# <int>
#1 999