Skip to contents

Create a reusable tidy policy that applies resp_tidy_json().

Usage

tidy_policy_json(subset_path = NULL, simplifyVector = FALSE)

Arguments

subset_path

(character) An optional vector indicating the path to the "real" object within the body of resp. 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 as data. If the desired part of the response body is in data$objects, the value of this argument should be c("data", "object").

simplifyVector

Should JSON arrays containing only primitives (i.e. booleans, numbers, and strings) be caused to atomic vectors?

Value

A list with class "nectar_tidy_policy" and elements tidy_fn and tidy_args.

Examples

tidy_policy_json(subset_path = "data")
#> $tidy_fn
#> function (resp, subset_path = NULL, simplifyVector = FALSE) 
#> {
#>     subset_path <- stbl::to_chr(subset_path)
#>     result <- httr2::resp_body_json(resp, simplifyVector = simplifyVector)
#>     result <- purrr::pluck(result, !!!subset_path)
#>     if (length(result)) {
#>         return(result)
#>     }
#>     return(NULL)
#> }
#> <bytecode: 0x55e271302ab8>
#> <environment: namespace:nectar>
#> 
#> $tidy_args
#> $tidy_args$subset_path
#> [1] "data"
#> 
#> $tidy_args$simplifyVector
#> [1] FALSE
#> 
#> 
#> attr(,"class")
#> [1] "nectar_tidy_policy"