jdi: a fast, portable C++11 library and Python/MATLAB/Octave toolbox for JSON, BJData, UBJSON and MessagePack with JData annotations
- Copyright: (C) 2026 Qianqian Fang <q.fang at neu.edu>
- License: BSD 3-Clause License or GNU General Public License version 3 or later, at your choice; see LICENSE_BSD.txt and LICENSE_GPLv3.txt
- Version: 0.1.0
- URL: https://neurojson.org
- Github: https://github.com/NeuroJSON/jdi
- Acknowledgement: This project is part of the NeuroJSON project supported by US National Institute of Health (NIH) grant U24-NS124027
- What's New
- Introduction
- Installation
- Using jdi in Python
- Using jdi in MATLAB and GNU Octave
- Using jdi in C++ and C
- The jdiconv command line tool
- Compile jdi
- Performance
- Contribution and Feedback
- Acknowledgement
- First release — one C++11 library, with no dependencies beyond the C++ standard library, that reads and writes JSON, BJData (Draft 4), UBJSON and MessagePack, and decodes and encodes JData annotations: N-D arrays of any element type and memory order, complex, sparse and compressed arrays, structure-of-arrays records, enumerations and more.
- Codecs built in — zlib, gzip, zstd, lz4, lz4hc, lzma, lzip and xz, plus base64; zlib is block-parallel (zlibmt: still a standard zlib stream, inflated on several threads), and payloads can be byte-shuffled.
- N-D chunks — arrays can be compressed in N-D tiles (
chunks="auto"picks tiles of about 256 KiB to 1 MiB), so that a slice, a line or a block is read, or written back, by decompressing only the tiles it meets. - JSON-Mmap —
.pmat/.jmatfiles carry a table of the byte locations of their values, so that one member is read, or updated in place, without parsing the rest of the file. - An intuitive C++ interface —
neurojson::jdata, written like nlohmann/json (j["a"]["b"] = 1, initializer lists,get<T>(),items(),parse/dump), with typed N-D arrays from nested braces (matrix({{1, 2}, {3, 4}})), your own types as records, and faster than nlohmann/json at building, looking up, parsing and binary I/O. - Python, MATLAB and Octave — a Python module (numpy arrays in and out, zero-copy views of
mapped files), and a MEX file that jsonlab's
loadjson,loadbj,savejsonandsavebjuse by themselves when it is on the path.
jdi ("JData I/O") is a fast and compact reader and writer of the JSON-based data formats of the
NeuroJSON project. A JSON or binary JSON document is read into a value (neurojson::jdata in
C++, a nlohmann/json-style class), or straight into the caller's objects (Python dicts and numpy
arrays, MATLAB structs and arrays), with the JData annotations it holds decoded on the way: an
object such as
{"_ArrayType_": "single", "_ArraySize_": [181, 217, 181], "_ArrayZipType_": "zstd",
"_ArrayZipSize_": [1, 7109137], "_ArrayZipData_": "KLUv/WBQ..."}becomes a 181 x 217 x 181 array of floats. Writing does the reverse, choosing the annotations a
value needs. The formats are chosen from the file name (.json/.jdt/.jnii/.jmsh/.jbids:
JSON; .bjd/.jdb/.bnii/.bmsh/.pmat/.jbat: BJData; .ubj: UBJSON; .msgpack/.mpk:
MessagePack) or from the content.
jdi follows the specifications it implements, and is checked against them and against jsonlab, the reference implementation, on every commit:
- JSON (RFC 8259), with exact, locale-independent number conversion and the shortest text that reads back the same double;
- BJData Draft 4 and UBJSON, including typed N-D arrays, structure-of-arrays containers and the extension type, and MessagePack;
- JData annotations, including compressed and chunked arrays, byte shuffling, enumerations, and JData files of several roots;
- JSON-Mmap tables for direct access to members.
The work is done in C++ with up to 8 threads: compression and decompression of large payloads,
of the chunks of an array, and of the arrays of a document. Among the codecs, lz4 is the
fastest; zstd gives smaller files at a similar speed when decoding; zlib/gzip are the most
widely readable (jsonlab reads them with no extra toolbox, Python with its standard library);
lzma/xz compress most, slowly.
jdi builds from source with CMake 3.10 or newer and a C++11 compiler (GCC 4.8 or newer, Clang,
Apple Clang, or MSVC; the CI uses Visual Studio 2022). The library, the jdiconv tool, the tests, the Python module
and the MEX file share one source tree:
git clone https://github.com/NeuroJSON/jdi.git jdi
cd jdi
cmake -S . -B build
cmake --build build -j
ctest --test-dir buildThis builds the static library libjdi.a (jdi_static.lib with MSVC), the shared library
libjdi.so/libjdi.dylib/jdi.dll, and jdiconv. cmake --install build installs them with
the headers (include/jdi).
The Python module installs with pip, which builds it with scikit-build-core:
pip install .For MATLAB and Octave, see Using jdi in MATLAB and GNU Octave.
import numpy as np
import jdi
obj = {"name": "scan", "image": np.zeros((256, 256, 64), np.uint16), "tags": ["a", "b"]}
jdi.save(obj, "scan.bjd", compression="zstd") # format from the file name
back = jdi.load("scan.bjd") # numpy arrays come back with their dtype and shape
b = jdi.dumps(obj) # BJData bytes
t = jdi.dumps(obj, format="json", indent=2) # JSON text (arrays as JData annotations)
obj = jdi.loads(b)
ann = jdi.encode(obj, compression="zlib") # the JData-annotated form (dicts)
obj = jdi.decode(ann)Reading part of a file:
jdi.save({"meta": {"subject": "s01"}, "image": vol, "n": 7}, "scan.pmat",
compression="zstd", shuffle=True, chunks="auto") # N-D tiles, with a JSON-Mmap table
jdi.load("scan.pmat", keys="n") # 7: only those bytes are parsed
jdi.load("scan.pmat", keys="$.meta.subject") # a JSON-Mmap path
jdi.load_region("scan.pmat", "image", (90,)) # one slice: only the tiles it meets are decoded
jdi.update("scan.pmat", "n", 8) # in place
jdi.update_region("scan.pmat", "image", (slice(0, 32), slice(0, 32), slice(0, 32)), block)
jdi.load("raw.pmat", view=True) # uncompressed arrays as zero-copy views of the fileThe options (compression, level, shuffle, chunks, soa, indent, nonfinite, ...),
the mapping between Python and stored values, and the JSON-Mmap functions are described in
bindings/python/README.md. jdi.set_threads(n) sets the number of
threads.
More complete programs are in examples/python: hello_jdi.py (documents,
text, bytes and members of a file), arrays.py (numpy arrays, compression, tiles, regions read
and written, zero-copy views) and tables.py (records as a structure of arrays, enumerations,
other Python values).
jdi gives jsonlab a compiled backend: the MEX file
jdi.mexa64 (MATLAB) or jdi.mex (Octave). Once it is on the path, jsonlab's loadjson,
loadbj, savejson and savebj use it by themselves (their Backend option: 'auto', the
default; 'mex' requires it; 'm' never uses it), with the same results as jsonlab's .m
code, 4 to 600 times faster. Options or values jdi does not handle fall back to the .m code.
To build it, compile the static library first, then run make_jdi in MATLAB or Octave:
cmake -S . -B build -DJDI_BUILD_SHARED=OFF -DJDI_BUILD_TESTS=OFF -DJDI_BUILD_TOOLS=OFF
cmake --build build -jcd bindings/matlab
make_jdi('../../build/libjdi.a')
addpath(pwd) % with jsonlab on the path too
data = loadbj('scan.bjd'); % jdi does the work
savejson('', data, 'FileName', 'scan.json', 'Compression', 'zlib');It can also be called directly:
[data, needdecode] = jdi('loadbj', 'scan.bjd', struct());
bytes = jdi('savebj', '', data, struct('Compression', 'zstd'));
jdi('threads', 4);test_jdi checks the MEX file against jsonlab's .m readers and writers (test_jdi('loadbj'),
'loadjson', 'savebj', 'savejson', 'mmap').
C++ (#include "jdi/jdi.hpp", C++11, link jdi_static or jdi::jdi in CMake) has a
nlohmann/json-style interface, neurojson::jdata. Code written for
nlohmann/json reads the same, and typed N-D arrays, compression and the binary formats come with it:
#include "jdi/jdi.hpp"
using neurojson::jdata;
using namespace neurojson::literals;
jdata j = {
{"name", "scan"},
{"tags", {"a", "b"}}, // a list
{"affine", neurojson::matrix({{1., 0.}, {0., 1.}})}, // a typed 2x2 double array
{"img", neurojson::zeros<float>({181, 217, 181})}, // a typed N-D array of zeros
{"spectrum", std::vector<double>(1024)} // a typed 1-D array
};
j["meta"]["subject"] = "s01"; // members are created on assignment
j["tags"].push_back("c");
std::string name = j["name"]; // or j["name"].get<std::string>()
std::vector<double> s = j["spectrum"]; // from a typed array or a list
auto img = j["img"].nd<float>(); // a typed view: img(i, j, k), img.shape()
img(90, 108, 90) = 1.0f;
for (auto& el : j.items()) { el.key(); el.value(); }
std::string text = j.dump(2); // JSON (small arrays as plain lists)
std::vector<std::uint8_t> bytes = jdata::to_bjdata(j); // also to_msgpack, to_ubjson
jdata k = jdata::parse(text), b = jdata::from_bjdata(bytes);
jdata t = R"({"a": [1, 2]})"_jdata;
t.at_path("$.a[1]") = 3; // JSON-Mmap paths, and JSON Pointers: at_pointer("/a/1")
neurojson::SaveOptions o;
o.jdata.compression = "zstd";
o.jdata.shuffle = -1; // byte-shuffle by the element size
o.jdata.chunk_auto = true; // N-D tiles for large arrays
j.save("scan.pmat", o); // format from the file name
jdata back = jdata::load("scan.pmat");Numeric arrays and matrices are written as nested braces. matrix (the same function as
ndarray) takes the shape from the nesting and the element type from the numbers, promoting
them as numpy does:
using neurojson::matrix;
jdata v = matrix({1, 2, 3}); // int32, 3
jdata m = matrix({{1, 2.5}, {3, 4}}); // double, 2x2 (any double makes it double)
jdata f = matrix({{1.f, 2.f}, {3.f, 4.f}}); // single, 2x2
jdata c = matrix({{{1, 2}, {3, 4}}, {{5, 6}, {7, 8}}}); // int32, 2x2x2
jdata u = matrix<std::uint8_t>({{1, 2}, {3, 4}}); // the type given: each number checked to fit
jdata z = neurojson::zeros<float>({64, 64, 64}); // a shape, zero-filledAny double, or floats mixed with integers, give double; floats alone single; integers
the widest of their types (signed when any is signed, wide enough for the unsigned ones);
booleans logical. Variables work as literals do, {{1}, {2}} is a 2x1 column, and ragged
braces are an error.
User types convert with a macro, or with to_jdata/from_jdata functions in their namespace,
as nlohmann/json's to_json/from_json; a list of them is stored as records (a structure of
arrays in BJData):
struct Point { double x, y; std::string label; };
JDI_DEFINE_TYPE(Point, x, y, label) // in Point's namespace
std::vector<Point> pts(1000);
jdata p = pts; // [{"x":..,"y":..,"label":..}, ...]
std::vector<Point> again = p;Where it differs from nlohmann/json, it does so to keep JData's types and arrays:
- numbers keep their C++ type (
int8_t,float,uint64_t, ...), as BJData can store it;get<T>()checks the range (neurojson::out_of_range) and the kind (neurojson::type_error); - a container of numbers (
std::vector<double>,std::array<int, 3>, ...) becomes a typed 1-D array, not a list of values (jdata::list(v)makes a list);j["v"][3]on such an array is atype_error: its elements are read and written throughj["v"].nd<double>(); dump()writes real arrays of 1 or 2 dimensions as plain lists, and larger or complex ones as JData annotations;dump(indent, true)annotates them all, which keeps their element types.
A lookup index makes member access in large objects fast; members keep their insertion order, as
in nlohmann::ordered_json. Measured with bench/bench_cxx_api.cpp (AMD Ryzen 9 5900X, one thread,
the best of 7 runs, milliseconds; nlohmann/json 3.11.3):
neurojson::jdata |
nlohmann::json |
nlohmann::ordered_json |
|
|---|---|---|---|
an object of 100000 members, j[key] = i |
11.7 | 16.3 | 12448 |
1e6 lookups in an object of 1000 members, j.at(key) |
37.8 | 73.2 | 1241 |
| 10000 small documents from initializer lists | 5.8 | 8.0 | 8.6 |
std::vector<double> of 1e6 to a value |
0.23 | 25.1 | 20.3 |
the value back to std::vector<double> |
1.1 | 1.3 | 1.3 |
| the 1e6 doubles to BJData / from BJData | 1.9 / 0.9 | 8.5 / 61.7 | 7.9 / 79.6 |
parse citm_catalog.json / canada.json |
3.2 / 10.4 | 7.9 / 23.2 | 12.0 / 23.1 |
dump citm_catalog.json / canada.json |
1.2 / 7.3 | 1.2 / 6.7 | 1.2 / 7.0 |
More complete programs are in examples/: hello_jdata.cpp (documents,
text and BJData), arrays.cpp (matrices, volumes, views, compression and tiles, reading single
members back) and user_types.cpp (your own types and standard containers); CMake builds them
and ctest runs them.
The same library is also reachable at a lower level, in namespace jdi: the parsers and writers
with all their options, parsing straight into your own objects (builder.hpp), N-D chunk access
(jdi::ChunkedArray) and in-place updates of files (jdi::update); include/jdi/jdi.hpp documents
them.
C (#include "jdi/jdi.h", C99) has the same interface as one constant struct, JData, so that
calls read as they do in the other languages:
#include "jdi/jdi.h"
double affine[4][4] = {{1, 0, 0, -90}, {0, 1, 0, -126}, {0, 0, 1, -72}, {0, 0, 0, 1}};
jdi_value* doc = JData.object();
JData.set(doc, "name", JData.string("scan")); /* set and append take ownership */
JData.set(doc, "age", JData.integer(31));
JData.set(doc, "affine", JData.matrix(JDI_DOUBLE, 4, 4, affine)); /* a typed 4x4 */
JData.set(doc, "subject", JData.parse("{\"id\": \"s01\"}"));
jdi_save_options o = JData.options();
o.compression = "zstd";
JData.save_with("scan.pmat", doc, &o); /* or JData.save(path, doc) */
jdi_value* back = JData.load("scan.pmat");
printf("%s %s\n", JData.as_string(JData.get(back, "name"), NULL),
JData.as_string(JData.get(back, "$.subject.id"), NULL)); /* or "/subject/id" */
char* text = JData.dumps(back, 2); /* JSON text */
JData.release_buffer(text);
JData.release(back);
JData.release(doc);Functions return NULL, or a negative number, on failure, and JData.error() says why. With C11,
JDI_VAL(x) makes a value of x's C type: JDI_VAL(31) an int32, JDI_VAL(2.5) a double,
JDI_VAL("text") a string. Every member of JData is also a plain function (jdi_load,
jdi_get, jdi_new_matrix, ...), and C++ code uses neurojson::jdata instead (in C++, jdi is a
namespace, so the JData object is declared for C only). See
examples/c/hello_jdata.c.
The headers in include/jdi document the rest: value.hpp and convert.hpp (the value and
its conversions), json.hpp and bjdata.hpp (the parsers and writers), jdata.hpp (the
annotations), codec.hpp (the codecs), mmap.hpp (JSON-Mmap tables) and builder.hpp (parsing
into your own objects).
jdiconv converts between the formats, compressing arrays on the way:
jdiconv data.json data.bjd # JSON to BJData
jdiconv -z zstd -s data.bjd data.jdt # to JSON with zstd-compressed, shuffled arrays
jdiconv -z zlib --chunks auto vol.bnii vol.pmat # N-D tiles
jdiconv -p data.bjd # a summary of the structure
jdiconv -v data.bjd # only check that it parsesjdiconv -h lists the options.
The CMake options are
| option | default | builds |
|---|---|---|
JDI_BUILD_SHARED |
ON |
the shared library, beside the static one |
JDI_BUILD_TOOLS |
ON |
jdiconv |
JDI_BUILD_TESTS |
ON |
the C++ and C tests (ctest), and the Python tests when the module is built |
JDI_BUILD_PYTHON |
OFF |
the Python module (needs pybind11 and numpy) |
JDI_BUILD_EXAMPLES |
ON |
the C++ examples (examples/cpp), run by ctest with the Python ones (examples/python) when the module is built |
JDI_BUILD_BENCH |
OFF |
bench_jdi, and bench_cxx_api (against nlohmann/json when its header is found, or -DJDI_NLOHMANN_INCLUDE=dir) |
for example
cmake -S . -B build -DJDI_BUILD_PYTHON=ON -DJDI_BUILD_BENCH=ON
cmake --build build -j
ctest --test-dir build --output-on-failure
PYTHONPATH=build/bindings/python python -m pytest tests/pythonThe CI (.github/workflows/ci.yml) builds and tests jdi with GCC (4.8, 5 and current), Clang,
AddressSanitizer and UndefinedBehaviorSanitizer on Linux, Apple Clang on macOS and MSVC on
Windows, and checks the MEX file against jsonlab in MATLAB and Octave. Python wheels are built by
.github/workflows/wheels.yml (cibuildwheel).
How an array is stored decides what reading it costs. A compressed array is always decoded
(there is no zero-copy view of compressed data); one compressed as a single payload is decoded
whole even to read one slice; one stored in N-D tiles is decoded only where a read meets it. The
options below are those of the Python module. In C++ they are members of
neurojson::SaveOptions::jdata (compression, level, shuffle, chunks/chunk_auto,
compress_min; see the example after the table); jdiconv, the C jdi_save_options and
jsonlab's options for the MEX file have most of them (the C interface has no chunk setting yet).
| the data, the need | options | what it gives |
|---|---|---|
| The default we recommend: numeric arrays where a small file and fast reads both matter | .pmat, compression="zstd", shuffle=True, chunks="auto" |
byte shuffling makes numbers compress much better (256 MiB of noisy doubles: 194 MB instead of 254 MB); tiles of 256 KiB to 1 MiB are decoded on all threads and make slices and blocks cheap |
| Files that jsonlab without zmat, or Python's standard library, must read | compression="zlib" (with shuffle and chunks as above) |
jdi's zlib is block-parallel (zlibmt) but its output is a standard zlib stream; within a few percent of zstd's size; single-threaded zstd decodes 10-40% faster, and with 8 threads zlib loads as fast or faster |
| The fastest saves and loads, size second | compression="lz4", shuffle=True |
1.5 to 2 times faster than zstd to write; files 5-10% larger |
| The fastest reads of large arrays from a local disk or RAM | no compression, .pmat, load(..., view=True) |
arrays are views of the mapped file: no copy, pages read when used (little-endian numeric arrays; complex and logical ones are copied) |
| Slices, lines or blocks of big arrays, updated in place | chunks={"shape": "auto", "index": True, "slack": 16}, then load_region / update_region |
the index finds a tile without reading the others; spare bytes after each tile let a changed tile be written back in place |
| Tables: a list of records, or columns | a list of dicts with the same keys (stored as structure-of-arrays columns), compression="zstd" or "lz4", shuffle=True |
string columns with repeated values are stored as enumerations by default: a 1-million-row table takes 5.7 MB, against Parquet's 10.0 MB |
| Many small arrays (a few hundred elements each) | no compression (the default compress_min=300 leaves arrays of up to 300 elements alone) |
10000 arrays of 100 doubles take 8.7 MB uncompressed and 9.9 MB with zstd, which is 3 to 5 times slower |
| Documents of many small values | .pmat (BJData with a JSON-Mmap table); load(..., keys=...) to read members |
one member read in a millisecond from a 25 MB document; update rewrites it in place |
| Text that people read or edit | .jmat/.json with the same options |
base64 payloads are a third larger than binary ones, and text is slower to parse |
The recommended default in C++:
neurojson::SaveOptions o;
o.jdata.compression = "zstd"; // or "zlib" for files every reader can open
o.jdata.shuffle = -1; // byte-shuffle by the element size
o.jdata.chunk_auto = true; // N-D tiles for arrays of 2 MiB or more
doc.save("scan.pmat", o); // doc: a neurojson::jdata
neurojson::LoadOptions lo;
lo.keys = {"meta", "n"}; // only these members, through the file's table
neurojson::jdata part = neurojson::jdata::load("scan.pmat", lo);A few rules behind these choices: chunks applies only to compressed arrays (without
compression it is ignored); update_region needs N-D tiles (chunks with a shape or
"auto"); and jdi.update writes a member with the options it is given, not those it was
saved with (tiled arrays keep their tiles), so pass the same compression, shuffle and
chunks again.
Measured with bench/bench_best.py and bench/bench_volume.py on an AMD Ryzen 9 5900X (8
threads for every library that has them), files on a RAM disk, the best of 3 runs (7 for the
volume); times in milliseconds. Each format is used at its best: HDF5 through h5py (with hdf5plugin's codecs),
Arrow IPC memory-mapped and Parquet through pyarrow, Blosc2 NDim arrays through python-blosc2.
"Load" includes summing the arrays, so that lazily mapped data is read too.
Eight arrays of 2048 x 2048 doubles (256 MiB, a smooth signal plus noise):
| format | save | load | read one array | update one array | MB |
|---|---|---|---|---|---|
jdi .pmat, uncompressed, view=True |
95 | 30 | 4.0 | 4.4 | 268.4 |
jdi .pmat, zstd + shuffle |
408 | 325 | 14.9 | 96 | 193.6 |
jdi .pmat, zlib + shuffle |
415 | 222 | 16.8 | 88 | 195.9 |
jdi .pmat, lz4 + shuffle |
228 | 272 | 29.6 | 48 | 203.5 |
| HDF5, uncompressed | 99 | 482 | 16.0 | 5.0 | 268.4 |
| HDF5, zstd | 390 | 644 | 32.9 | 41 | 254.6 |
| HDF5, Blosc2 zstd | 2135 | 2148 | 221.3 | 259 | 203.6 |
| Arrow IPC, uncompressed | 103 | 63 | 11.5 | 783 | 268.5 |
| Arrow IPC, zstd | 166 | 140 | 68.7 | 1217 | 253.6 |
| Parquet, zstd | 743 | 121 | 26.6 | 884 | 262.0 |
numpy .npz, compressed |
7014 | 1211 | 116.9 | 8343 | 242.1 |
jdi makes the smallest files, reads one compressed array about as fast as any other format, and
updates one in place; Arrow, Parquet and .npz write the whole file again to change one array.
Arrow and Parquet load all of these arrays faster than jdi does compressed, but they barely
compress them (254 to 262 MB, against jdi's 194); uncompressed, jdi's views are the fastest.
A table of 1 million rows (int64, two float64, int32, bool, a 20-value category and a 50000-value string column):
| format | save | load all | read one column | MB |
|---|---|---|---|---|
jdi .pmat, zstd + shuffle |
88 | 94 | 4.3 | 5.7 |
jdi .pmat, uncompressed, view=True |
55 | 86 | 0.10 | 32.6 |
| Arrow IPC, zstd | 106 | 998 | 10.6 | 10.9 |
| Parquet, zstd | 167 | 1027 | 9.6 | 10.0 |
| HDF5, zstd | 560 | 681 | 10.4 | 95.6 |
"Load all" gives numpy arrays and Python strings; kept as an Arrow table, Arrow's load takes a few milliseconds. Reading the string column alone, Arrow is faster (46 ms against jdi's 75).
A 3-D volume (the colin27 atlas, 181 x 217 x 181 float32, 28 MB) in 32^3 tiles:
| format | save | whole | slice | line | 32^3 block | voxel | update block | update voxel | MB |
|---|---|---|---|---|---|---|---|---|---|
| jdi, zstd, tiles + index + slack | 28 | 7.9 | 0.69 | 0.23 | 0.40 | 0.10 | 2.2 | 0.86 | 13.4 |
| jdi, lz4, tiles + index + slack | 13 | 6.5 | 0.46 | 0.17 | 0.24 | 0.07 | 1.1 | 0.23 | 14.2 |
| jdi, zstd, one payload | 95 | 8.4 | 6.94 | 6.91 | 7.42 | 7.05 | 12.5 | ||
| Blosc2 NDim, zstd level 1 | 130 | 13.4 | 2.06 | 0.52 | 0.54 | 0.25 | 8.2 | 0.60 | 12.4 |
| HDF5, zstd | 45 | 19.0 | 2.62 | 0.59 | 0.88 | 0.28 | 2.3 | 0.49 | 12.6 |
The same volume in one compressed payload costs a full decode for any read. In tiles, jdi reads the whole volume and every region 1.4 to 4 times faster than Blosc2 and HDF5 with the same tile shape and codec; with zstd, Blosc2 and HDF5 update a single voxel faster.
Documents of many small values (a 25 MB list of GitHub event records; Python):
| save | load | read one member | update one member | |
|---|---|---|---|---|
jdi .pmat |
65 | 138 | 0.97 | 2.6 |
| orjson | 24 | 123 | 142 | 169 |
| msgspec (MessagePack) | 22 | 107 | 128 | 154 |
| pysimdjson (lazy) | 158 | 23 |
Loading a whole document takes about as long with every library (the time goes on creating the Python objects). Saving one from Python objects is where jdi is behind (3 times orjson); reading or changing one member through the JSON-Mmap table is 25 to 150 times faster than parsing the document.
sh bench/compare.sh builds jdi and runs the comparison on your machine, against numpy's .npz,
HDF5 (h5py, hdf5plugin), Apache Arrow and Parquet (pyarrow), Blosc2, pyjdata, bjdata, orjson and
msgpack, in a Python venv it makes; --full adds bench_best.py, which the tables above come
from. The CI runs it on every commit and posts the tables on the run's summary page.
bench/README.md has the full results, MATLAB and Octave included.
jdi is an open-source project. This means you can not only use it and modify it as you wish, but also you can contribute your changes back to jdi so that everyone else can enjoy the improvement. For anyone who want to contribute, please download the jdi source code from its source code repository by using the following command:
git clone https://github.com/NeuroJSON/jdi.git jdior browse the github site at https://github.com/NeuroJSON/jdi
You can make changes to the files as needed. Once you are satisfied with your changes, and ready to share them with others, please submit your changes as a "pull request" on github. The project maintainer, Dr. Qianqian Fang, will review the changes and choose to accept the patch.
We appreciate any suggestions and feedback from you. Please use the NeuroJSON forum to report any questions you may have regarding jdi:
jdi's DEFLATE (zlib, gzip) and Zstandard codecs, its parsers and writers are its own. It bundles
the below open-source libraries, unmodified (see licensing.json):
- LZ4: https://github.com/lz4/lz4 (version 1.10.0)
- Copyright (c) 2011-2020, Yann Collet
- License: BSD 2-Clause License (third_party/lz4/LICENSE)
- Used for: the lz4 and lz4hc codecs
- LZMA SDK: https://www.7-zip.org/sdk.html (version 26.00)
- Author: Igor Pavlov
- License: public domain
- Used for: the lzma, lzip and xz codecs
- Ryu: https://github.com/ulfjack/ryu
- Copyright 2018 Ulf Adams
- License: Apache License 2.0 or Boost Software License 1.0
- Used for: the shortest decimal text of floating-point numbers in the JSON writer
- fast_float: https://github.com/fastfloat/fast_float (version 6.1.6)
- Copyright (c) 2021 The fast_float authors (Daniel Lemire and contributors)
- License: Apache License 2.0, MIT License or Boost Software License 1.0
- Used for: exact, locale-independent number parsing in the JSON reader
