tests/testthat/test-toJSON-AsIs.R

test_that("Encoding AsIs", {
  expect_equal(toJSON(list(1), auto_unbox=TRUE), "[1]");
  expect_equal(toJSON(list(I(1)), auto_unbox=TRUE), "[[1]]");
  expect_equal(toJSON(I(list(1)), auto_unbox=TRUE), "[1]");

  expect_equal(toJSON(list(x=1)), "{\"x\":[1]}");
  expect_equal(toJSON(list(x=1), auto_unbox=TRUE), "{\"x\":1}");
  expect_equal(toJSON(list(x=I(1)), auto_unbox=TRUE), "{\"x\":[1]}");

  expect_equal(toJSON(list(x=I(list(1))), auto_unbox=TRUE), "{\"x\":[1]}");
  expect_equal(toJSON(list(x=list(I(1))), auto_unbox=TRUE), "{\"x\":[[1]]}");
});

Try the jsonlite package in your browser

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

jsonlite documentation built on June 22, 2024, 11:05 a.m.