Changelog
Source:NEWS.md
zujson 0.1.1
Bug fixes
A
POSIXltdata frame column, and aPOSIXltpassed tojson_write_ndjson(), now raisezujson_unsupported_type. Both used to skip the check and write the 11 broken-down time fields as data: in an 11-row frame, row i became field i (#40).A
POSIXcta fraction of a second before midnight is written as23:59:59. Floating-point rounding could print hour24instead, as in"1969-12-31T24:00:00Z", which no RFC 3339 parser accepts (#41).A classed vector whose storage the class cannot mean – a
Datestored as character, a factor with integer levels, a data frame that is not a list of vector columns – raiseszujson_unsupported_typeinstead of a bare R error that escaped thezujson_errorcontract. An all-NAlogicalDateorPOSIXct, such asstructure(NA, class = "Date"), is written asnull(#43).A zero-row data frame is charged one nesting level, for the
[]it writes, not two. It used to be refused at a depthjson_parse()reads back (#57).data_frame = TRUEno longer slows to quadratic time on keys chosen to collide in its index. The key hash is now seeded per call and fully mixed; 2^15 colliding keys took 5.7 s, against 0.014 s for ordinary ones, and could not be interrupted until the end (#44).An integer too wide for 64 bits parses to the nearest
double. About 1 in 1000 came back one unit in the last place off, and differently from the same number written with.0(#46).Every
json_parse_ndjson()error names its line, including those raised while building a record: an embedded NUL, nesting too deep, a duplicate key in a data frame record, the cell limit (#54).Condition messages are valid UTF-8 and marked as such. A long non-ASCII key or column name could be cut mid-character (#53).
zujson_info()$max_df_cellsreports a fractional option as the whole number of cells the parser enforces (#55).A body built by
json_write_ndjson()past 2^31 - 1 bytes raiseszujson_write_error, pointing tojson_write_ndjson_raw(), instead of a bare error frompaste().json_write_ndjson_raw()builds its bytes directly rather than from that string, so it has no such ceiling (#47).json_parse_file()reads a file with a non-ASCII name in any locale. It now reads the bytes in R and parses them by the raw route; the C layer used to open a translated copy of the path, which under the C locale named a file that does not exist (#50).json_parse_file()reads a FIFO or pipe, and a file namedstdinorclipboardreads the file rather than that device (#66).Native-encoded strings in a UTF-8 session, the usual output of
rawToChar()andreadLines(), are passed to the parser and writer as they are rather than through a conversion, which madejson_write()about 8x slower on them (#67).json_write_ndjson()names the record an error comes from (#70).A data frame with no columns and no
namesattribute is written as[]rather than refused (#73).A condition message that quotes a name holding invalid bytes stays valid UTF-8, showing each bad byte as
<xx>(#76).The native memory behind a parse or a write can no longer leak if R fails an allocation at the moment it is handed to R. The external pointer that owns it is now made before the memory exists (#52).
Behaviour changes
A string that is not valid in the encoding it declares raises
zujson_parse_errorinjson_parse()andjson_parse_ndjson(), andzujson_write_errorin the writers, andjson_validate()returnsFALSEfor it. R’s conversion used to rewrite such bytes as text, so a body read withreadLines()under the C locale came back as"caf<c3><a9>", and"<81>"was sent for a latin1 byte with no character (#42).bit64::integer64vectors are written as the 64-bit integers they hold, withNAasnull. They used to fall through to their storage type and be written as the doubles their bits spell, so1went out as5e-324(#48).The data frame cell limit,
zujson_info()$max_df_cells, now bounds the whole document rather than each frame in it, as?json_parsedescribes it. Many frames each under the limit used to be accepted together, however far past it their total went (#45).json_parse_ndjson()accepts a UTF-8 byte order mark only at the start of the body, and a body that is only a BOM is empty. A BOM at the start of any later line was accepted, and a BOM-only first line was an error (#56).
Documentation
-
vignette("zujson")is a Get started tutorial that takes one API response through parsing, writing, raw bytes, a failure and NDJSON. The website adds articles on malformed or untrusted input and on coming from jsonlite.
zujson 0.1.0
CRAN release: 2026-10-02
First release. Everything below is the work that went into it, newest first.
Bug fixes
A data frame’s row objects are now charged a nesting level in both directions. Parsing, they were not charged at all, so a document one level too deep to parse as a list parsed as a frame; writing, a list column was charged twice, so a frame whose JSON sat exactly at the 1000-level limit was rejected.
zujson_info()$max_depthnow means the same thing whichever options are passed.DateandPOSIXctoutside0000-01-01to9999-12-31now raisezujson_write_error. Both are doubles in R, so they reach far past what a timestamp can be written as:1e300produced"2030437271-06-06T-596523:-14:-8Z", and converting it toint64_ton the way was undefined behaviour rather than merely wrong.A string whose
Encoding()is"bytes"now raiseszujson_arg_errorwhen parsing andzujson_write_errorwhen writing, instead of the baresimpleErrorthatRf_translateCharUTF8()raises from inside R. Everything this package can fail with is azujson_erroragain. Pass the bytes as a raw vector, which is what the raw path is for.data_frame = TRUEno longer drops a value when one record carries the same key twice. It raiseszujson_parse_error: a column has one cell per record, and plain parsing keeps both values, so quietly keeping one made an option about shape change content.
Data frames
Building a frame is now linear in the length of the input rather than quadratic in the number of distinct keys. The union of the keys is collected through a hash index instead of a scan of the keys so far, and cells are filled by one pass over the records instead of a lookup per cell that rescanned the record. A 4000 x 2000 frame went from 69s to 1.6s.
-
The size of a frame is now capped. Because the result is rectangular, its size is set by the union of the keys and not by how much JSON arrived: 5000 records sharing no keys is a 5000 x 5000 frame — 96 MB — from 72 kB of body, which is a denial-of-service path for a package meant to be pointed at untrusted bodies. A limit on the body cannot stand in for one here, because the growth is quadratic in it. More than
zujson_info()$max_df_cellscells now raiseszujson_limit_error, as the offending column appears rather than after the allocation.The default is 50 million cells, roughly 400 MB of doubles, plus the same order again for the pointer matrix the records are scattered through — 100k rows by 200 columns is 20 million, so a real tabular response has room to spare.
options(zujson.max_df_cells = )changes it for the session, andzujson_info()$max_df_cellsreports the limit actually in force. Setting it larger than any frame that could be built switches the check off, at the price that an oversized body then raises R’s own allocation error rather than azujson_limit_error. simplify = "none"takes precedence overdata_frame = TRUE, and says so. That mode’s promise is that every JSON array arrives as an R list; the two options are not combined.A number too large for any finite
doublenow parses asInfinstead of failing the whole read. RFC 8259 puts no limit on the magnitude of a number, so1e309is valid JSON, and rejecting it let one absurd value anywhere in a response body make the entire body unparseable. The value is the oneas.numeric()gives the same token, so an integer wider thanint64reads as the nearest double.json_validate("1e309")isTRUEfor the same reason. The bare literalsInfinity,-InfinityandNaNare not JSON and are still rejected.json_parse_file()on a directory now raiseszujson_io_erroron every platform. It already did on macOS and Windows, wherefopen()refuses a directory; on Linuxfopen()succeeds, so yyjson failed later with a memory allocation error and the call raisedzujson_parse_errorinstead. The path is a directory either way, which is an io problem, not a malformed document.
Parsing
simplifygains named modes."preserve"(the default, and whatTRUEhas always meant) keeps a mixed-kind array as a list;"coerce"promotes it to a character vector following R’s own rules, so[1, "a"]becomesc("1", "a")and a JSONnullbecomesNArather than the string"NA"."none"isFALSE.TRUEandFALSEkeep working and mean exactly what they did, so nothing written against the old API changes meaning.data_frame = TRUEturns a non-empty array whose elements are all objects into a data frame, wherever one appears. Columns are the union of the keys in first-seen order and a missing key reads asNA, so ragged records still give a rectangular result. Columns simplify with the activesimplifymode. Off by default: the documented type mapping is unchanged unless you ask.
Infrastructure
Differential tests against
jsonlite, intests/testthat/test-interop-jsonlite.R. Two tables over JSON text: where the two packages agree, and a divergence table pinning the places they are meant not to —[]islogical(0),preservekeeps[1, "a"]a list, there is no matrix detection, and data frames are opt-in. The second table is the useful one: it fails if a change quietly makes this package morejsonlite-like than the documented mapping says.jsonliteis a suggested package and the tests skip without it.Conformance against
nst/JSONTestSuite, intools/jsontestsuite.R. Every file is handed tojson_validate()as raw bytes — the suite is full of deliberately invalid UTF-8 and embedded NULs, which a text read would mangle. The package accepts all 95 files it must accept and rejects all 188 it must reject; of the 35 implementation-defined files it accepts 12, the rejections being invalid UTF-8 and lone surrogates. The script pins an upstream commit so the result cannot drift under it, and needs the network only once.Sanitizer and randomised-input CI.
tools/sanitizer-exercise.Rdrives the C layer using nothing but base R, with most of its effort on the error paths, where an R error longjmps past the explicit free;hardening.yamlruns it under clang-asan, clang-ubsan and gcc-asan, and fuzzes the parser separately.tests/testthat/test-fuzz.Rruns a smaller version of the same idea on every test run.
Initial feature set
The v1 work, previously labelled 0.1.0 — a version number, not a release.
-
json_parse(),json_parse_raw()andjson_parse_file()turn JSON into R vectors and lists. Arrays simplify to atomic vectors only when their elements share a type, so a value’s type survives the round trip;simplify = FALSEturns simplification off entirely. -
json_write()andjson_write_raw()serialize R as JSON text or as UTF-8 bytes. A fully named vector or list becomes an object, anything else becomes an array, and length-1 atomic vectors unbox unless wrapped inI(). -
json_validate()reports whether input parses, without building a result. -
json_parse_ndjson(),json_write_ndjson()andjson_write_ndjson_raw()handleapplication/x-ndjson(JSON Lines): one JSON value per line, parsed and written with the same type mappings as single documents. Parsing always returns a list of records and reports the line number on failure; a data frame writes one object per row. There is noprettyoption, because indented JSON contains newlines and would break the framing. -
zujson_info()reports the package version, the vendored yyjson version and the nesting limit. - Every failure raises a condition inheriting from
zujson_error:zujson_parse_error,zujson_write_error,zujson_unsupported_type,zujson_depth_error,zujson_io_errorandzujson_arg_error. - A leading UTF-8 byte order mark is ignored rather than rejected, and a
POSIXltis refused rather than serialized as its 11 internal fields. - yyjson 0.12.0 is vendored under
src/vendor/yyjson; no system library is needed.