SymbolixAU / jsonify

R package to convert R objects to JSON
https://symbolixau.github.io/jsonify/
Other
67 stars 10 forks source link

data.frame list column boxed too deep #44

Closed SymbolixAU closed 5 years ago

SymbolixAU commented 5 years ago
df <- structure(list(id = c("1", "2"), val = list("a", 1:2)), class = "data.frame", row.names = 1:2)
to_json( df ) 
# [{"id":"1","val":[["a"]]},{"id":"2","val":[[1,2]]}] 

Maybe this should be

# [{"id":"1","val":["a"]},{"id":"2","val":[1,2]}] 

but it needs to be consistent with the rules: https://symbolixau.github.io/jsonify/articles/jsonify.html#complex---lists

Because building this up suggests it's right as it is

to_json("a")
# ["a"]

to_json( list("a"))
# '[["a"]]

to_json( df[1, "val"] )
# '[["a"]]'

to_json( df[, "val"] )
# '[["a"],[1,2]]'

to_json( df )
# '[{"id":"1","val":[["a"]]},{"id":"2","val":[[1,2]]}]'