tests/testthat/test-keys.R

test_that("json_keys works", {
  expect_equal(
    json_keys(c(
      '{"a": 1, "b": 2}',
      '{"x": 1, "y": 2}',
      "[1, 2]"
    )),
    list(
      c("a", "b"),
      c("x", "y"),
      c(0L, 1L)
    )
  )
})


test_that("json_path_exists works", {
  expect_equal(
    json_path_exists(
      c(
        '{"a": 1}',
        '{"b": 2}',
        "[1, 2]",
        NA_character_
      ),
      "$.a"
    ),
    c(TRUE, FALSE, FALSE, NA)
  )
})

Try the jsontools package in your browser

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

jsontools documentation built on March 22, 2021, 5:06 p.m.