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

Adding option to overwrite "single null" values #32

Open
ecqiu opened this issue Mar 15, 2024 · 1 comment
Open

Adding option to overwrite "single null" values #32

ecqiu opened this issue Mar 15, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@ecqiu
Copy link

ecqiu commented Mar 15, 2024

RcppSimdJson has the option to overwrite single null values with the 'single_null' option in RcppSimdJson::fparse, this can be useful e.g. in overwriting NULLs to NAs when reading the JSON rather than later for speed purposes.

Should yyjsonr also have this option?

Here is an example of how the option works:

> RcppSimdJson::fparse('{"x":null,"y":null,"z":3}')
$x
NULL

$y
NULL

$z
[1] 3
> RcppSimdJson::fparse('{"x":null,"y":null,"z":3}',single_null = NA)
$x
[1] NA

$y
[1] NA

$z
[1] 3

Related PR:
#29

@m-muecke
Copy link

m-muecke commented Dec 6, 2024

I'm not sure if this issue covers the same issue, but it would be lovely if a list with NULLs has the option of getting converted to NAs like {jsonlite} does it with the simplify = TRUE flag, for reference the implementation: https://github.com/jeroen/jsonlite/blob/86f481d34eb4e7893e32a88608ce220421f59c41/R/list_to_vec.R#L1

x <- "[{\"transaction\":[{\"price\":[0.2715,0.1030,null,null],\"missing\":[null,null,null,null]}]}]"
jsonlite::fromJSON(x, simplifyDataFrame = FALSE)
#> [[1]]
#> [[1]]$transaction
#> [[1]]$transaction[[1]]
#> [[1]]$transaction[[1]]$price
#> [1] 0.2715 0.1030     NA     NA
#> 
#> [[1]]$transaction[[1]]$missing
#> [1] NA NA NA NA
yyjsonr::read_json_str(x, opts = yyjsonr::opts_read_json(obj_of_arrs_to_df = FALSE, arr_of_objs_to_df = FALSE))
#> [[1]]
#> [[1]]$transaction
#> [[1]]$transaction[[1]]
#> [[1]]$transaction[[1]]$price
#> [1] 0.2715 0.1030     NA     NA
#> 
#> [[1]]$transaction[[1]]$missing
#> [[1]]$transaction[[1]]$missing[[1]]
#> NULL
#> 
#> [[1]]$transaction[[1]]$missing[[2]]
#> NULL
#> 
#> [[1]]$transaction[[1]]$missing[[3]]
#> NULL
#> 
#> [[1]]$transaction[[1]]$missing[[4]]
#> NULL

Created on 2024-12-06 with reprex v2.1.1

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