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

Option to read empty array to NULL or vector instead of list #52

Open
JosiahParry opened this issue Sep 1, 2024 · 1 comment
Open
Labels
NULL/empty handling Handling of NULL/Empty values

Comments

@JosiahParry
Copy link

The details in the following JSON is parsed into a list() by yyjsonr {"error":{"code":400,"message":"Invalid URL","details":[]}}

I know that details will only every be a character vector. The list() is causing an issue with existing code that expects either a NULL or a character vector. Is there an option that can be set to change the behavior of yyjsonr in this case?

@coolbutuseless coolbutuseless added the NULL/empty handling Handling of NULL/Empty values label Sep 1, 2024
@coolbutuseless
Copy link
Owner

coolbutuseless commented Sep 1, 2024

Thanks for raising this issue. There's a few things around NULL/empty handling that are on my list - I'll add this to it.

Notes on arbitrary R objects when JSON []-array is empty

  • Inopts_read_json()

    • Add empty_array = ...
    • Value can be any R object.
    • By default: list(), but common alternatives would be NULL, "" (empty string), NA
  • Empty json []-array handling is here:

    // Empty []-array becomes an empty list

Also need to think about json {}-objects

  • Should the same be done for empty {}-objects?
  • Currently: empty json {}-objects produce an empty named list() in R
  • Empty {}-object handling could go about here:
    R_xlen_t n = (R_xlen_t)yyjson_get_len(obj);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NULL/empty handling Handling of NULL/Empty values
Projects
None yet
Development

No branches or pull requests

2 participants