tests/testthat/test-libjson-validator.R

test_that("test that the validator properly deals with escaped characters", {
  #create random strings
  mychars <- c('a', 'b', " ", '"', "\\", "\t", "\n", "'", "/", "#", "$")
  createstring <- function(length) {
    paste(mychars[ceiling(runif(length, 0, length(mychars)))], collapse = "")
  }

  for (i in 1:200) {
    #create some random strings to validate
    x <- createstring(i)
    expect_true(validate(toJSON(x)))
  }
})

Try the jsonlite package in your browser

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

jsonlite documentation built on April 4, 2025, 5:24 a.m.