A policy to parse a response body as JSON
Source:R/resp_tidy_json_tibblify.R
tidy_policy_json_tibblify.RdCreate a reusable tidy policy that applies resp_tidy_json_tibblify().
Arguments
- spec
(
tspecorNULL) A specification used bytibblify::tibblify()to parse the extracted body ofresp. WhenspecisNULL(the default),tibblify::tibblify()will attempt to guess a spec.- unspecified
(
length-1 character) A string that describes what happens if the extracted body ofrespcontains fields that are not specified inspec. Whiletibblify::tibblify()defaults toNULLfor this value, we set it tolistso that the body will still parse whenrespcontains extra data without throwing errors.- subset_path
(
character) An optional vector indicating the path to the "real" object within the body ofresp. For example, many APIs return a body with information about the status of the response, cache information, perhaps pagination information, and then the actual data in a field such asdata. If the desired part of the response body is indata$objects, the value of this argument should bec("data", "object").
See also
Other opinionated response parsers:
req_tidy_policy(),
resp_tidy(),
resp_tidy_json(),
resp_tidy_json_tibblify(),
resp_tidy_unknown(),
tidy_policy_body_auto(),
tidy_policy_json(),
tidy_policy_prepare(),
tidy_policy_unknown()
Examples
tidy_policy_json_tibblify(subset_path = "data")
#> $tidy_fn
#> function (resp, spec = NULL, unspecified = "list", subset_path = NULL)
#> {
#> result <- resp_tidy_json(resp = resp, subset_path = subset_path,
#> simplifyVector = FALSE)
#> if (length(result)) {
#> rlang::check_installed("tibblify", "to tidy the JSON response body.")
#> return(tibblify::tibblify(result, spec = spec, unspecified = unspecified))
#> }
#> return(NULL)
#> }
#> <bytecode: 0x55e26e375318>
#> <environment: namespace:nectar>
#>
#> $tidy_args
#> $tidy_args$spec
#> NULL
#>
#> $tidy_args$unspecified
#> [1] "list"
#>
#> $tidy_args$subset_path
#> [1] "data"
#>
#>
#> attr(,"class")
#> [1] "nectar_tidy_policy"