How do I contend with NULLs in nested JSON when converting to df using fromJSON, bind_rows, and map?



Hi. I am trying to convert some JSON into a data frame but am having trouble with null values downstructure, which show up as a pairlist of length 0 when coming through jsonlite.

Jeroen and @jennybryan had some back and forth here, though I wasn't sure if it had been resolved. For now, I'm using this solution but was wondering if there was a more purrrlicious way to do it. Reprex below is supposed to be minimal, but normally I would get my end result by piping the map result into bind_rows(.id = ticker).

#> Warning: package 'stringr' was built under R version 3.4.4
#> Attaching package: 'jsonlite'
#> The following object is masked from 'package:purrr':
#>     flatten

jsonwnulls <- '{"AAPL":{"quote":{"open":162.62,"high":165.42,"low":162.41,"close":163.65}},"FAKE":{"quote":{"open":null, "high": 0.99, "low": 0.52, "close":0.6355}}}'

jsonlitewnulls <- fromJSON(jsonwnulls)

map(jsonlitewnulls, bind_rows)
#> Error in bind_rows_(x, .id): Argument 1 is a list, must contain atomic vectors

Created on 2018-04-25 by the reprex package (v0.2.0).