Package: jdata
JData for Python - lightweight and serializable data annotations for PythonCopyright: (C) Qianqian Fang (2019-2022) <q.fang at neu.edu>License: Apache License, Version 2.0Version: 0.5.3URL:https://github.com/NeuroJSON/pyjdataTheJData Specificationdefines a lightweight
language-independent data annotation interface targetted at
storing and sharing complex data structures across different programming
languages such as MATLAB, JavaScript, Python etc. Using JData formats, a
complex Python data structure can be encoded as adictobject that is easily
serialized as a JSON/binary JSON file and share such data between
programs of different languages.How to installGithub: download fromhttps://github.com/NeuroJSON/pyjdataPIP: runpip install jdataseehttps://pypi.org/project/jdata/This package can also be installed on Ubuntu 21.04 or Debian Bullseye viasudo apt-get install python3-jdataOn older Ubuntu or Debian releases, you may install jdata via the below PPA:sudo add-apt-repository ppa:fangq/ppa
sudo apt-get update
sudo apt-get install python3-jdataDependencies:numpy: PIP: runpip install numpyorsudo apt-get install python3-numpy(optional)bjdata: PIP: runpip install bjdataorsudo apt-get install python3-bjdata, seehttps://pypi.org/project/bjdata/, only needed to read/write BJData/UBJSON files(optional)lz4: PIP: runpip install lz4, only needed when encoding/decoding lz4-compressed data(optional)backports.lzma: PIP: runsudo apt-get install liblzma-devandpip install backports.lzma(needed for Python 2.7), only needed when encoding/decoding lzma-compressed data(optional)blosc2: PIP: runpip install blosc2, only needed when encoding/decoding blosc2-compressed dataReplacingpipbypip3if you are using Python 3.x. If eitherpiporpip3does not exist on your system, please runsudo apt-get install python3-pipPlease note that in some OS releases (such as Ubuntu 20.04), python2.x and python-pip
are no longer supported.One can also install this module from the source code. To do this, you first
check out a copy of the latest code from Github bygit clone https://github.com/NeuroJSON/pyjdata.git
    cd pyjdatathen install the module to your local user folder bypython3 setup.py install --useror, if you prefer, install to the system folder for all users bysudo python3 setup.py installPlease replacepythonbypython3if you want to install it for Python 3.x instead of 2.x.Instead of installing the module, you can also import the jdata module directly from
your local copy by cd the root folder of the unzipped pyjdata package, and runimport jdata as jdHow to useThe PyJData module is easy to use. You can use theencode()/decode()functions to
encode Python data into JData annotation format, or decode JData structures into
native Python data, for exampleimport jdata as jd
import numpy as np

a={'str':'test','num':1.2,'list':[1.1,[2.1]],'nan':float('nan'),'np':np.arange(1,5,dtype=np.uint8)}
jd.encode(a)
jd.decode(jd.encode(a))
d1=jd.encode(a,{'compression':'zlib','base64':1})
d1
jd.decode(d1,{'base64':1})One can further save the JData annotated data into JSON or binary JSON (UBJSON) files using
thejdata.savefunction, or loading JData-formatted data to Python usingjdata.loadimport jdata as jd
import numpy as np

a={'str':'test','num':1.2,'list':[1.1,[2.1]],'nan':float('nan'),'np':np.arange(1,5,dtype=np.uint8)}
jd.save(a,'test.json')
newdata=jd.load('test.json')
newdataPyJData supports multiple N-D array data compression/decompression methods (i.e. codecs), similar
to HDF5 filters. Currently supported codecs includezlib,gzip,lz4,lzma,base64and variousblosc2compression methods, includingblosc2blosclz,blosc2lz4,blosc2lz4hc,blosc2zlib,blosc2zstd. To apply a selected compression method, one simply set{'compression':'method'}as
the option tojdata.encodeorjdata.savefunction;jdata.loadorjdata.decodeautomatically
decompress the data based on the_ArrayZipType_annotation present in the data. Onlyblosc2compression methods support multi-threading. To set the thread number, one should define annthreadvalue in the option (opt) for both encoding and decoding.UtilityOne can convert from JSON based data files (.json, .jdt, .jnii, .jmsh, .jnirs) to binary-JData
based binary files (.bjd, .jdb, .bnii, .bmsh, .bnirs) and vice versa using commandpython3 -mjdata /path/to/text/json/file.json # convert to /path/to/text/json/file.jdb
python3 -mjdata /path/to/text/json/file.jdb  # convert to /path/to/text/json/file.json
python3 -mjdata -h                           # show help infoTestTo see additional data type support, please run the built-in test using below commandpython3 -m unittest discover -v test