tests/testthat/test-json_promotion.R

js <- r"(
[
  {"a":1.234560},
  {"a":2},
  {"a":"apple"}
])"


test_that("numeric promotion to string instead of list works", {

  res <- read_json_str(js)
  expect_identical(res$a, list(1.234560, 2L, "apple"))
  
  res <- read_json_str(js, promote_num_to_string = FALSE)
  expect_identical(res$a, list(1.234560, 2L, "apple"))

  res <- read_json_str(js, promote_num_to_string = TRUE) 
  expect_identical(res$a, c("1.234560", "2", "apple"))
})

Try the yyjsonr package in your browser

Any scripts or data that you put into this service are public.

yyjsonr documentation built on May 29, 2024, 3:01 a.m.