Skip to content

Per-element control of unbox #75

@mmuurr

Description

@mmuurr

{jsonify} is great, but I struggle to use it as a mediator for communication with some external APIs due to one missing feature: element-level control of the unbox parameter (in to_json()).
A third-party API might expect this object:

{
  "unboxed_prop": "foo",
  "boxed_prop": ["variable", "length", "array"]
}

With {jsonlite}, we'd coerce the corresponding R object to something like:

x <- some_data_here()  ## may return a vector of length 0, 1, or more
list(
  unboxed_prop = "foo",
  boxed_prop = I(x)  ## 'protect' the value here with I()/AsIs
) |>
jsonlite::toJSON(auto_unbox = TRUE)

With I(x), boxed_prop is guaranteed to be JSON-encoded as an array regardless of length(x).

Is something like this possible with {jsonify}?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions