Learn R Programming

rjsoncons

This package provides functions to query (filter or transform), pivot (convert from array-of-objects to object-of-arrays, for easy import as 'R' data frame), search, patch (edit), and validate (against JSON Schema) 'JSON' and 'NDJSON' strings, files, or URLs. Query and pivot support JSONpointer, JSONpath or JMESpath expressions. The implementation uses the jsoncons header-only library; the library is easily linked to other packages for direct access to 'C++' functionality not implemented here.

Installation and loading

Install the released package version from CRAN

install.packages("rjsoncons", repos = "https://CRAN.R-project.org")

Install the development version with

if (!requireNamespace("remotes", quiety = TRUE))
    install.packages("remotes", repos = "https://CRAN.R-project.org")
remotes::install_github("mtmorgan/rjsoncons")

Attach the installed package to your R session with

library(rjsoncons)

Use cases

The introductory vignette outlines common use cases, including:

  • Filter large JSON or NDJSON documents to extract records or elements of interest.
  • Extract deeply nested elements.
  • Transform data for more direct incorporation in R data structures.
  • 'Patch' JSON strings programmatically, e.g., to update HTTP request payloads.
  • Validate JSON documents against JSON schemas

The jsoncons C++ header-only library is a very useful starting point for advanced JSON manipulation. The vignette outlines how rjsoncons can be used by other R packages wishing to access the C++ library.

Next steps

See the introductory vignette for additional details.

Copy Link

Version

Install

install.packages('rjsoncons')

Monthly Downloads

1,471

Version

1.3.2

License

BSL-1.0

Maintainer

Martin Morgan

Last Published

March 15th, 2025

Functions in rjsoncons (1.3.2)

j_data_type

Detect JSON and NDJSON data and path types
j_schema_is_valid

Validate JSON documents against JSON Schema
jsonpath

JSONpath, JMESpath, or JSONpointer query of JSON / NDJSON documents; use j_query() instead
j_flatten

Flatten and find keys or values in JSON or NDJSON documents
version

Version of jsoncons C++ library
as_r

Parse JSON or NDJSON to R
j_query

Query and pivot JSON and NDJSON documents
j_patch_apply

Patch or compute the difference between two JSON documents