jstring <- jsonString $ new("
{
\" foo\" : \" hello\" ,
\" bar\" : {\" x\" : 1, \" y\" : 2},
\" baz\" : [9, 99, null],
\" qux\" : [null, [0, 1], {\" a\" : 1000}]
}
" )
Extract a JSON value
jstring $ at(" foo" )
# # "hello"
jstring $ at(" bar" , " y" )
# # 2
jstring $ at(" baz" , 2 )
# # null
jstring $ erase(" baz" )
jstring
# # {
# # "bar": {
# # "x": 1,
# # "y": 2
# # },
# # "foo": "hello",
# # "qux": [
# # null,
# # [
# # 0,
# # 1
# # ],
# # {
# # "a": 1000
# # }
# # ]
# # }
Check existence of a property
jstring $ hasKey(" bar" )
# # [1] TRUE
jstring $ is(" object" )
# # [1] TRUE
jstring $ addProperty(" new" , " [4,5]" )
jstring
# # {
# # "bar": {
# # "x": 1,
# # "y": 2
# # },
# # "foo": "hello",
# # "new": [
# # 4,
# # 5
# # ],
# # "qux": [
# # null,
# # [
# # 0,
# # 1
# # ],
# # {
# # "a": 1000
# # }
# # ]
# # }
jstring $ update(
" {
\" foo\" : \" goodbye\" ,
\" quux\" : 10000
}"
)
jstring
# # {
# # "bar": {
# # "x": 1,
# # "y": 2
# # },
# # "foo": "goodbye",
# # "new": [
# # 4,
# # 5
# # ],
# # "quux": 10000,
# # "qux": [
# # null,
# # [
# # 0,
# # 1
# # ],
# # {
# # "a": 1000
# # }
# # ]
# # }
jspatch <- " [
{\" op\" : \" remove\" , \" path\" : \" /foo\" },
{\" op\" : \" replace\" , \" path\" : \" /qux/2\" , \" value\" : 9999}
]"
jstring $ patch(jspatch )
# # {
# # "bar": {
# # "x": 1,
# # "y": 2
# # },
# # "new": [
# # 4,
# # 5
# # ],
# # "quux": 10000,
# # "qux": [
# # null,
# # [
# # 0,
# # 1
# # ],
# # 9999
# # ]
# # }
jstring <- jsonString $ new("
{
\" foo\" : \" hello\" ,
\" bar\" : {\" x\" : 1, \" y\" : 2},
\" baz\" : [9, 99, null],
\" qux\" : [null, [0, 1], {\" a\" : 1000}]
}
" )
jstring $ erase(" baz" )$ addProperty(" new" , " [4,5]" )$ update(
" {
\" foo\" : \" goodbye\" ,
\" quux\" : 10000
}"
)
jstring
# # {
# # "bar": {
# # "x": 1,
# # "y": 2
# # },
# # "foo": "goodbye",
# # "new": [
# # 4,
# # 5
# # ],
# # "quux": 10000,
# # "qux": [
# # null,
# # [
# # 0,
# # 1
# # ],
# # {
# # "a": 1000
# # }
# # ]
# # }