Skip to content

serialize not converting NA's to nulls for number type items #87

Description

@collinschwantes

Having an issue with data serialization where numeric NA values are not converted to nulls when serializing the data.
They are instead added as "NA".

### repex for jsonvalidate


json_schema <- '{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Vector Competence Data Standard v1.0.0",
  "description":"A minimal flexible data standard viral vector competence studies",
  "type": "object",
  "properties": {
    "mean_temp_reared":{
        "description":"Average temperature recorded during rearing in celsius. See http://www.ebi.ac.uk/efo/EFO_0001702",
        "examples": [25.2, 30, 18, 27.6],
        "type":"array",
        "items":{
            "type": ["number", "null"],
            "minItems":1
          }
    }
  }
}'
 
num_data <- list("mean_temp_reared" = c(1,2,2.4,NA))

num_obj <- jsonvalidate::json_schema$new(schema = json_schema)

num_json <- num_obj$serialise(num_data)

num_obj$validate(num_json,verbose = TRUE)



Session info

R version 4.5.0 (2025-04-11)
Platform: aarch64-apple-darwin20
Running under: macOS Sequoia 15.7.4

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.1

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/New_York
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

loaded via a namespace (and not attached):
 [1] BiocManager_1.30.25 compiler_4.5.0      R6_2.6.1            tools_4.5.0        
 [5] rstudioapi_0.17.1   curl_6.2.3          Rcpp_1.0.14         V8_8.2.0           
 [9] jsonvalidate_1.5.0  jsonlite_2.0.0      renv_1.0.11    

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions