Skip to main content

Encoding and decoding Python data structrues using portable JData-annotated formats

Project description

JData for Python - a lightweight and portable data annotation method

The JData Specification defines 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 a dict object that is easily serialized as a JSON/binary JSON file and share such data between programs of different languages.

How to install

Optional Dependency (if reading or writing Binary JData/UBJSON files):

Replacing pip by pip3 if you are using Python 3.x. If either pip or pip3 does not exist on your system, please run

    sudo apt-get python-pip python3-pip

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 by

    git clone https://github.com/fangq/pyjdata.git
    cd pyjdata

then install the module to your local user folder by

    python setup.py install --user

or, if you prefer, install to the system folder for all users by

    sudo python setup.py install

Please replace python by python3 if you want to install it for Python 3.x instead of 2.x.

How to use

The PyJData module is easy to use. You can use the encode()/decode() functions to encode Python data into JData annotation format, or decode JData structures into native Python data, for example

import 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 the jdata.save function, or loading JData-formatted data to Python using jdata.load

import 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')
newdata

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jdata-0.3.5.tar.gz (7.3 kB view details)

Uploaded Source

File details

Details for the file jdata-0.3.5.tar.gz.

File metadata

  • Download URL: jdata-0.3.5.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.6.9

File hashes

Hashes for jdata-0.3.5.tar.gz
Algorithm Hash digest
SHA256 727875900bc3b9920f41df6b8140e9c36187dbf992305b75804977bac3758d14
MD5 ebb77283849313877d5f8c1e9404d153
BLAKE2b-256 9c25f5328bdd95379bf0c3792878e9752ac6bb5624849d5898ae1641f3397edb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page