Lightweight JSON Parsing and Serialization

Converts between JSON text and ordinary R vectors and lists through a small, predictable set of functions, backed by vendored 'yyjson' < https://github.com/ibireme/yyjson> and requiring no system JSON library. Parsing accepts character, raw and file input and reports failures through structured conditions; serialization writes UTF-8 bytes suitable for use directly as an HTTP request body. The type mapping is deliberately narrow and fully documented, so what goes in and what comes out are both predictable.


zujson

CRANstatus Lifecycle:experimental R-CMD-check coverage

zujson is a JSON parser and writer that converts between JSON and ordinary R vectors and lists by a small, documented type mapping.

  • It is built on yyjson, whose sources it bundles, so it needs no system library and no package outside base R.
  • No value changes type to fit a vector: an array of numbers and strings stays a list, unless you pass simplify = "coerce".
  • It reads and writes raw bytes as well as strings, which is how an HTTP body arrives and leaves.
  • Every failure is a condition that inherits from zujson_error, so one handler catches them all.

Installation

Install the released version from CRAN:

install.packages("zujson")

Or the development version from GitHub:

# install.packages("pak")
pak::pak("pedrobtz/zujson")

Usage

library(zujson)

json_parse() reads JSON into R. An object becomes a named list, and an array whose elements share a type becomes an atomic vector:

str(json_parse('{"ok": true, "ids": [1, 2, 3], "next": null}'))
#> List of 3
#>  $ ok  : logi TRUE
#>  $ ids : int [1:3] 1 2 3
#>  $ next: NULL

json_write() goes the other way. A fully named list becomes an object, a vector an array, and a length-one vector a bare value:

cat(json_write(list(query = "cats", limit = 10L, tags = c("a", "b"))))
#> {"query":"cats","limit":10,"tags":["a","b"]}

zujson also reads files and NDJSON, builds data frames from arrays of records, and checks whether input is valid JSON; Get started shows each of these.

Learn more

zujson is narrower than jsonlite by design; use jsonlite when you need matrices, custom serializers or input too large to hold in memory.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("zujson")

0.1.1 by Pedro Baltazar, a day ago


https://github.com/pedrobtz/zujson, https://pedrobtz.github.io/zujson/


Report a bug at https://github.com/pedrobtz/zujson/issues


Browse source code at https://github.com/cran/zujson


Authors: Pedro Baltazar [aut, cre, cph] , YaoYuan [ctb, cph] (author of the bundled yyjson library)


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports utils

Suggests jsonlite, knitr, rmarkdown, testthat, withr


Suggested by zumime, zutoml.


See at CRAN