jsonAccess: Access to the value of a JSON string

Description Usage Arguments Value Note See Also Examples

Description

Access to the value of a JSON string by giving a sequence of keys.

Usage

1
jsonAccess(json, path, toJSON = FALSE, fromJSON = FALSE)

Arguments

json

a JSON string

path

character vector, sequence of keys

toJSON

logical, whether to apply toJSON to the input

fromJSON

logical, whether to apply fromJSON to the output

Value

A json string if fromJSON=FALSE, a R object if fromJSON=TRUE.

Note

Instaed of using the option toJSON=TRUE, you can apply toJSON before; this allows you to apply it with its options. Same remark for the option toJSON=FALSE.

See Also

jsonElemsAt

Examples

1
2
3
4
5
6
7
8
9
json <- "{\"a\":{\"b\":8,\"c\":[1,2]},\"b\":null}"
jsonAccess(json, "a")
jsonAccess(json, "b")
jsonAccess(json, "X")
jsonAccess(json, c("a","c"))
# get the result as a R object:
jsonAccess(json, c("a","c"), fromJSON=TRUE)
# same as:
jsonAccess(json, c("a","c")) %>% jsonlite::fromJSON(.)

stla/jsonAccess documentation built on May 30, 2019, 5:47 p.m.