tests/testthat/test-json.R

context("JSON")

test_that("safeFromJSON is safe", {
  # Valid JSON works
  a <- safeFromJSON('{"key": "value"}')
  expect_equal(a, list(key="value"))

  # File paths fail
  expect_error(safeFromJSON("/etc/passwd")) # error from jsonlite::parse_json()

  # Remote URLs fail
  expect_error(safeFromJSON("http://server.org/data.json")) # error from jsonlite::parse_json()
})

Try the plumber package in your browser

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

plumber documentation built on Sept. 7, 2022, 1:05 a.m.