json_array_agg: Aggregate into a JSON array

View source: R/array_utils.R

json_array_aggR Documentation

Aggregate into a JSON array

Description

Aggregate into a JSON array

Usage

json_array_agg(x)

Arguments

x

Vector to collapse into JSON array.

Value

A json2 vector of length one with the elements of x collapsed to a JSON array.

Examples

json_array_agg(1:3)
json_array_agg(json2(c('{"a": 1}', '{"b": 2}')))

# can be quite useful in combination with `dplyr::group_by()`
if (require("dplyr", quietly = TRUE, warn.conflicts = FALSE)) {
  tibble::tibble(
    group = c(1, 1, 2, 2),
    json = c(1:4)
  ) %>%
    dplyr::group_by(group) %>%
    dplyr::summarise(json = json_array_agg(json))
}

mgirlich/jsontools documentation built on March 21, 2023, 9:10 a.m.