Perhaps we could convert to a data.frame and then subset
library(jsonlite)
library(dplyr)
library(purrr)
library(stringr)
fromJSON(myjson) %>%
invoke(data.frame, .) %>%
filter(select(cur_data(), where(is.character)) %>%
map(~ str_detect(., 'station')) %>%
reduce(`|`)
)
-output
# time id user.id user.game user.hobby
#1 today 123 456 playstation <NA>
#2 today 555 42 play station
If the data is heavily nested, there is a flatten
argument in fromJSON
which is by default FALSE
fromJSON(myjson, flatten = TRUE) %>%
filter(select(cur_data(), where(is.character)) %>%
map(~ str_detect(., 'station')) %>%
reduce(`|`)
)
-output
# time id user.id user.game user.hobby user.user.id user.user.game user.user.hobby
#1 today 123 456 playstation <NA> NA <NA> <NA>
#2 today 555 42 play station 10 play station
CLICK HERE to find out more related problems solutions.