README.md

jsonmatch

Travis-CI Build Status AppVeyor Build Status Coverage Status

Simple JSON matching.

Get it

devtools::install_github('chiefBiiko/jsonmatch')

Usage

jsonmatch::jsonmatch(json, pattern, auto_unbox=FALSE, strict=TRUE)

Return character, json. JSON subset.

pattern allows matching keys of JSON arrays and objects. Its syntax rules are simple:

Note that a colon within an array subset pattern is only valid if it is trailing, indicating to select all array elements with an index in the range of [low:] to length(array) - 1 aka the end of the array. The wildcard character in an object subset pattern matches any alphanumeric character sequence. Wildcard matching cannot be used if object keys contain non-alphanumeric characters [^[:alnum:]].

For the rationale of auto_unbox check out boxjson. If strict is TRUE and jsonlite::validate(json) evaluates to FALSE an error is thrown.

# some JSON
some.json <- jsonlite::toJSON(list(list(name='herman', gang='almans'), 
                                   list(name='habibo', gang=c('haji', '419'))))

# peek at it
cat('some JSON:\n', some.json, sep='')
some JSON:
[{"name":["herman"],"gang":["almans"]},{"name":["habibo"],"gang":["haji","419"]}]
# who u with
gangs <- jsonmatch::jsonmatch(some.json, '[0:].gang')
cat('gangs:\n', gangs, sep='')
gangs:
[["almans"],["haji","419"]]

TODO

License

MIT



chiefBiiko/jsonmatch documentation built on May 23, 2019, 8:36 a.m.