We are excited to announce that the JSONLab project, as the official reference library
for both the JData and BJData
specifications, is funded by the US National Institute of Health (NIH) as
part of the NeuroJSON project (https://neurojson.org).
The goal of the NeuroJSON project is to develop human-readable, scalable and
future-proof neuroimaging data standards and data sharing services. All data
produced from the NeuroJSON project will be using JSON/Binary JData formats as the
underlying serialization standards and use the lightweight JData specification as
language-independent data annotation standard, all of which have been evolved from
the over a decade development of JSONLab.
JSONLab v2.9.8 - code named "Micronus - beta" - is the beta-release of the next milestone -
JSONLab v3.0 - containing a number of key feature enhancement and bug fixes. The major
new features include
exporting JSON Memory-Map for rapid disk-map like JSON/binary JSON reading
and writing, implementing JSON-Mmap Spec v1 Draft 1
supporting JSONPath query to MATLAB data and JSON/binary JSON file and streams,
(breaking) upgrading the supported BJData spec to V1 Draft 2
where the default numerical data byte order changed from Big-Endian to Little-Endian,
adding initial support to JData _DataLink_
decoding to link multiple JSON/binary JSON files
There have been many major updates added to this release since the previous
release v2.0 in June 2020. A list of the major changes are summarized below
(with key features marked by *), including the support to BJData Draft-2 specification,
new interface functions savejd/loadjd, and options to use MATLAB/Octave built-in
jsonencode/jsondecode functions. The octave-jsonlab package has also been
included in the official distributions of Debian Bullseye and Ubuntu 21.04 or newer.
2020-07-07 [6a8ce93] fix string encoding over 399 characters, close #65
2020-06-14 [5a58faf] fix DESCRIPTION date bug
2020-06-14 [9d7e94c] match octave description file and upstream version number
2020-06-14 [a5b6170] fix warning about lz4encode file name
Please note that the savejson/loadjson in both JSONLab v2.0-v3.0 are
compliant with JData Spec Draft 3; the savebj/loadbj`` in JSONLab v3.0 is
compatible to BJData spec Draft 2, which contains breaking feature changes
compared to those in JSONLab v2.0.
The BJData spec was derived from UBJSON spec Draft 12, with the
following breaking differences:
BJData adds 4 new numeric data types: uint16 [u], uint32 [m], uint64 [M]
and float16 [h] (supported in JSONLab v2.0 or newer)
BJData supports an optimized ND array container (supported in JSONLab since 2013)
BJData does not convert NaN/Inf/-Inf to null (supported in JSONLab since 2013)
BJData Draft 2 changes the default byte order to Little-Endian instead of Big-Endian (JSONLab 3.0 or later)
BJData only permits non-zero-fixed-length data types as the optimized array type, i.e. only UiuImlMLhdDC are allowed
To avoid using the new features, one should attach 'UBJSON',1 and 'Endian','B'
in the savebj command as
JSONLab is an open-source JSON/UBJSON/MessagePack encoder and decoder written
completely in the native MATLAB language. It can be used to convert most MATLAB
data structures (array, struct, cell, struct array, cell array, and objects) into
JSON/UBJSON/MessagePack formatted strings and files, or to parse a
JSON/UBJSON/MessagePack file into a MATLAB data structure. JSONLab supports both
MATLAB and GNU Octave (a free MATLAB clone).
Compared to other MATLAB/Octave JSON parsers, JSONLab is uniquely lightweight,
ultra-portable, producing dependable outputs across a wide-range of MATLAB
(tested on R2008) and Octave (tested on v3.8) versions. It also uniquely supports
BinaryJData/UBJSON/MessagePack data files as binary-JSON-like formats, designed
for efficiency and flexibility with loss-less binary storage. As a parser written
completely with the native MATLAB language, it is surprisingly fast when reading
small-to-moderate sized JSON files (1-2 MB) with simple hierarchical structures,
and is heavily optimized for reading JSON files containing large N-D arrays
(known as the "fast array parser" in loadjson).
JSON (JavaScript Object Notation) is a highly portable,
human-readable and "fat-free" text format
to represent complex and hierarchical data, widely used for data-exchange in applications.
UBJSON (Universal Binary JSON) is a binary JSON format,
designed to specifically address the limitations of JSON, permitting the
storage of binary data with strongly typed data records, resulting in smaller
file sizes and fast encoding and decoding. MessagePack is another binary
JSON-like data format widely used in data exchange in web/native applications.
It is slightly more compact than UBJSON, but is not directly readable compared
to UBJSON.
We envision that both JSON and its binary counterparts will play important
roles for storage, exchange and interoperation of large-scale scientific data
among the wide-variety of tools. As container-formats, they offer both the
flexibility and generality similar to other more sophisticated formats such
as HDF5, but are significantly
simpler with a much greater software ecosystem.
Towards this goal, we have developed the JData Specification (http://github.com/NeuroJSON/jdata)
to standardize serializations of complex scientific data structures, such as
N-D arrays, sparse/complex-valued arrays, trees, maps, tables and graphs using
JSON/binary JSON constructs. The text and binary formatted JData files are
syntactically compatible with JSON/UBJSON formats, and can be readily parsed
using existing JSON and UBJSON parsers. JSONLab is not just a parser and writer
of JSON/UBJSON data files, but one that systematically converts complex scientific
data structures into human-readable and universally supported JSON forms using the
standardized JData data annotations.
The installation of JSONLab is no different from installing any other
MATLAB toolbox. You only need to download/unzip the JSONLab package
to a folder, and add the folder's path to MATLAB/Octave's path list
by using the following command:
addpath('/path/to/jsonlab');
If you want to add this path permanently, you can type pathtool,
browse to the JSONLab root folder and add to the list, then click "Save".
Then, run rehash in MATLAB, and type which savejson, if you see an
output, that means JSONLab is installed for MATLAB/Octave.
If you use MATLAB in a shared environment such as a Linux server, the
best way to add path is to type
mkdir ~/matlab/
nano ~/matlab/startup.m
and type addpath('/path/to/jsonlab') in this file, save and quit the editor.
MATLAB will execute this file every time it starts. For Octave, the file
you need to edit is ~/.octaverc, where ~ is your home directory.
To use the data compression features, please download the ZMat toolbox from
https://github.com/fangq/zmat/releases/latest and follow the instruction to
install ZMat first. The ZMat toolbox is required when compression is used on
MATLAB running in the -nojvm mode or GNU Octave, or 'lzma/lzip/lz4/lz4hc'
compression methods are specified. ZMat can also compress large arrays that
MATLAB's Java-based compression API does not support.
JSONLab provides a pair of functions, loadjson -- a JSON parser, and savejson --
a MATLAB-to-JSON encoder, to read/write the text-based JSON; it also provides
three equivalent pairs -- loadbj/savebj for binary JData, loadubjson/saveubjson
for UBJSON and loadmsgpack/savemsgpack for MessagePack. The load* functions
for the 3 supported data formats share almost the same input parameter format,
similarly for the 3 save* functions (savejson/saveubjson/savemsgpack).
These encoders and decoders are capable of processing/sharing almost all
data structures supported by MATLAB, thanks to jdataencode/jdatadecode -
a pair of in-memory data converters translating complex MATLAB data structures
to their easy-to-serialized forms according to the JData specifications.
The detailed help information can be found in the Contents.m file.
In JSONLab 2.9.8 and later versions, a unified file loading and saving interface
is provided for JSON, binary JSON and HDF5, including loadjd and savejd
for reading and writing below files types:
Under the examples folder, you can find several scripts to demonstrate the
basic utilities of JSONLab. Running the demo_jsonlab_basic.m script, you
will see the conversions from MATLAB data structure to JSON text and backward.
In jsonlab_selftest.m, we load complex JSON files downloaded from the Internet
and validate the loadjson/savejson functions for regression testing purposes.
Similarly, a demo_ubjson_basic.m script is provided to test the saveubjson
and loadubjson functions for various matlab data structures, and
demo_msgpack_basic.m is for testing savemsgpack and loadmsgpack.
Please run these examples and understand how JSONLab works before you use
it to process your data.
Under the test folder, you can find a script to test individual data types and
inputs using various encoders and decoders. This unit testing script also serves as
a specification validator to the JSONLab functions and ensure that the outputs
are compliant to the underlying specifications.
Starting from JSONLab v2.0, we provide a pair of functions, jsave/jload to store
and retrieve variables from the current workspace, similar to the save/load
functions in MATLAB and Octave. The files that jsave/jload reads/writes is by
default a binary JData file with a suffix .jamm. The file size is comparable
(can be smaller if use lzma compression) to .mat files. This feature
is currently experimental.
The main benefits of using .jamm file to share matlab variables include
a .jamm file can be 50% smaller than a .mat file when using
jsave(..., "compression","lzma"); the only drawback is longer saving time.
a .jamm file can be readily read/opened among many programming environments, including
Python, JavaScript, Go, Java etc, where .mat file support is not generally available.
Parsers of .jamm files are largely compatible with UBJSON's parsers available at
http://ubjson.org/?page_id=48
a .jamm file is quasi-human-readable, one can see the internal data fields
even in a command line, for example using strings -n 2 file.jamm | astyle,
making the binary data easy to be understood, shared and reused.
jsave/jload can also use MessagePack and JSON formats as the underlying
data storage format, addressing needs from a diverse set of applications.
MessagePack parsers are readily available at https://msgpack.org/
jsave% save the current workspace to jamdata.jammjsavemydata.jammjsave('mydata.jamm','vars',{'var1','var2'})
jsave('mydata.jamm','compression','lzma')
jsave('mydata.json','compression','gzip')
jload% load variables from jamdata.jamm to the current workspacejloadmydata.jamm % load variables from mydata.jamm
vars=jload('mydata.jamm','vars',{'var1','var2'}) % return vars.var1, vars.var2jload('mydata.jamm','simplifycell',0)
jload('mydata.json')
Despite the use of portable data annotation defined by the JData Specification,
the output JSON files created by JSONLab are 100% JSON compatible (with
the exception that long strings may be broken into multiple lines for better
readability). Therefore, JSONLab-created JSON files (.json, .jnii, .jnirs etc)
can be readily read and written by nearly all existing JSON parsers, including
the built-in json module parser in Python.
However, we strongly recommend one to use a lightweight jdata module,
developed by the same author, to perform the extra JData encoding and decoding
and convert JSON data directly to convenient Python/Numpy data structures.
The jdata module can also directly read/write UBJSON/Binary JData outputs
from JSONLab (.bjd, .ubj, .bnii, .bnirs, .jamm etc). Using binary JData
files are expected to produce much smaller file sizes and faster parsing,
while maintaining excellent portability and generality.
In short, to conveniently read/write data files created by JSONLab into Python,
whether they are JSON based or binary JData/UBJSON based, one just need to download
the below two light-weight python modules:
To install these modules on Python 2.x, please first check if your system has
pip and numpy, if not, please install it by running (using Ubuntu/Debian as example)
To install these modules for Python 3.x, please replace pip by pip3.
If one prefers to install these modules globally for all users, simply
execute the above commands using
sudo pip install jdata
sudo pip install bjdata
The above modules require built-in Python modules json and NumPy (numpy).
Once the necessary modules are installed, one can type python (or python3), and run
请发表评论