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

Explicit scalars #24

Open
anthonynorth opened this issue Jan 19, 2024 · 1 comment
Open

Explicit scalars #24

anthonynorth opened this issue Jan 19, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@anthonynorth
Copy link

Could we add support for explicitly treating a vector as scalar? This is the reverse of auto_unbox = TRUE and opting out with I(); instead everything is vector and we explicitly decorate a length-1 vector as scalar. This also gives us the option of throwing errors when our "scalar" isn't length-1.

Example R to JSON:

Input

list(my_scalar = "foo", my_vector = "bar")

Output

{"my_scalar":"foo","my_vector":["bar"]}

{jsonlite}'s approach to this is to decorate scalars with a class ("scalar").

jsonlite::toJSON(list(my_scalar = jsonlite::unbox("foo"), my_vector = "bar"))
@coolbutuseless coolbutuseless added the enhancement New feature or request label Jan 20, 2024
@OlaCaster
Copy link

+1 on this request; jsonlite::unbox offers great flexibility

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

No branches or pull requests

3 participants