While no cross-language marshaling scheme will be perfect, but I think when it comes to R lists there can be a distinction between named (representing an JSON object) and unnamed (representing a generic JSON array). Current conversions look like so, along with what I think are reasonable expectations in the comments.
library(jsonify)
unnamed_empty_list <- list() ## names() -> NULL
named_empty_list <- unnamed_empty_list |> rlang::set_names(character(0)) ## names() -> character(0)
str(unnamed_empty_list)
#> list()
str(named_empty_list)
#> Named list()
json_empty_array <- "[]"
json_empty_object <- "{}"
## expect: []
to_json(unnamed_empty_list)
#> []
## expect: {}
to_json(named_empty_list)
#> []
## expect: unnamed list()
from_json(json_empty_array) |> str()
#> list()
## expect: named list()
from_json(json_empty_object) |> str()
#> NULL
Thoughts on supporting this distinction between a named and unnamed list? (This really only affects the empty list case.)
While no cross-language marshaling scheme will be perfect, but I think when it comes to R lists there can be a distinction between named (representing an JSON object) and unnamed (representing a generic JSON array). Current conversions look like so, along with what I think are reasonable expectations in the comments.
Thoughts on supporting this distinction between a named and unnamed list? (This really only affects the empty list case.)