Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Named list should be a JSON object, regardless of length #79

Open
mmuurr opened this issue Feb 14, 2024 · 0 comments
Open

Proposal: Named list should be a JSON object, regardless of length #79

mmuurr opened this issue Feb 14, 2024 · 0 comments

Comments

@mmuurr
Copy link

mmuurr commented Feb 14, 2024

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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant