I'm trying to output a data.frame
as json. This works fine for the columns that are always populated. However, it seems that if the column is NA
for any row, then the entire column is missing from the resulting json. Is there a fix or configuration option I'm missing?
@elbamos I can not reproduce that the whole column is missing, but I can reproduce that the column is missing from that row's output.
data.frame(a = 1:3, b = c(1, NA, 3)) %>% jsonlite::toJSON()
#> [{"a":1,"b":1},{"a":2},{"a":3,"b":3}]
There is currently no configuration option. File in question
I believe better defaults are needed.
Which makes more sense to you?
data.frame(a = 1:3, b = c(1, NA, 3)) %>% jsonlite::toJSON(na = "null")
#> [{"a":1,"b":1},{"a":2,"b":null},{"a":3,"b":3}]
data.frame(a = 1:3, b = c(1, NA, 3)) %>% jsonlite::toJSON(na = "string")
#> [{"a":1,"b":1},{"a":2,"b":"NA"},{"a":3,"b":3}]
I am leaning towards null
as there are no types in JSON and to avoid a true "NA" value in the column value.
I'm working on a fix for this. Currently trying to figure out how to get the something like @json(na="null")
work the block comment
I see that this issue is closed but I still have the same problem and I can't find any documentation on how to deal with this. @schloerke Could you help me with this? Thank you
@kintany this is plumber hotline support, how may I help you today? Would you mind sharing your code so we can replicate what you are experiencing.
Maybe try
#* @serializer json list(na = "string")
@meztez Oh great, this actually worked, thanks:
#* @serializer unboxedJSON list(na = NULL)
Most helpful comment
@meztez Oh great, this actually worked, thanks:
#* @serializer unboxedJSON list(na = NULL)