Skip to main content

Bidirectional conversion between JSON(-LD) and iRODS AVUs

Project description

Bidirectional conversion between JSON(-LD) and iRODS AVUs

Rationale

JSON is a flexible and easy to use format for storing (nested) data. At the same time it can remain human readable. It can therefore be an ideal method for storing metadata in iRODS. However, iRODS uses Attribute, Value, Unit triples. Its largest drawback being the lack of nesting.

This Python module describes a method for converting JSON to AVU triples and back again (bidirectional).

Design goals

  • Bijection between JSON <-> AVU
    • i.e no limit on the characters used in an attribute
    • i.e being able to maintain order in arrays
  • Lean JSON -> AVU conversion.
    • Don't explode the JSON unnecessarily in AVUs
  • Keep Attribute->Value pairs the same in JSON and AVUs. So values remain easily accessible from within iRODS
  • Compatible with existing or additional AVUs
  • Compatible/aware of JSON-LD
  • Unicode-safe

Implementation

The unit is field is being used for the following purposes:

  1. The JSON-AVU namespace
  2. The parent object (0 by default)
  3. The object type (o, s, b, a, n, z, e)
  4. The array index

AVUs only allow a string value. The types are converted as follows:

  • s: string
  • o: object ("o" + object_id)
  • b: boolean ("True" or "False")
  • n: number (String value of float or int)
  • z: null (".")
  • e: empty string (".") (special case as AVUs don't allow empty values)
  • a: empty array (".")

Installation

Either clone the git repository, or use pip to install the module into your Python (virtual) environment:

pip install irods_avu_json

From within iRODS

This Python module, by itself, has no interaction or awareness of iRODS.

There is a companion repository irods_avu_json-ruleset that contains all the iRODS rules, policies, and microservices to make the conversion code operational in iRODS.

Docker

A description of a docker container running the ruleset, its microservices, and python dependencies exists in the irods_avu_json-docker repository. You can use this to quickly try out this module and test its functionality.

Example output

Source:
{
    "k1": "v1",
    "k2": {
        "k3": "v2",
        "k4": "v3"
    },
    "k5": [
        "v4",
        "v5"
    ],
    "k6": [
        {
            "k7": "v6",
            "k8": "v7"
        }
    ]
}
AVUs:
      A       V               U
     k1      v1        root_0_s
     k2      o1       root_0_o1
     k3      v2        root_1_s
     k4      v3        root_1_s
     k5      v4      root_0_s#0
     k5      v5      root_0_s#1
     k6      o2     root_0_o2#0
     k7      v6        root_2_s
     k8      v7        root_2_s
JSON:
{
    "k1": "v1",
    "k2": {
        "k3": "v2",
        "k4": "v3"
    },
    "k5": [
        "v4",
        "v5"
    ],
    "k6": [
        {
            "k7": "v6",
            "k8": "v7"
        }
    ]
}

Development helpers

Use the conversion.py script for easy development. Compatible with Python 2 and 3.

python conversion.py inputs/basic.json

Testing

Tests can be run from the top-level directory (requires Python3).

python3 -m unittest test

Limits

On the AVU side

  • If two AVUs have the same attribute and unit but different values only the last one ends up in the JSON

Authors

Paul van Schayck (p.vanschayck@maastrichtuniversity.nl), Ton Smeele, Daniel Theunissen and Lazlo Westerhof

Copyright and license

(c) Maastricht University (c) Utrecht University

Apache License 2.0

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

irods_avu_json-2.2.0.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

irods_avu_json-2.2.0-py3-none-any.whl (23.1 kB view details)

Uploaded Python 3

File details

Details for the file irods_avu_json-2.2.0.tar.gz.

File metadata

  • Download URL: irods_avu_json-2.2.0.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.52.0 CPython/3.8.6

File hashes

Hashes for irods_avu_json-2.2.0.tar.gz
Algorithm Hash digest
SHA256 375cdf5558c11422b8f0e2eb24d2dd66bf018a75cc11c574fe6896d012a52771
MD5 51a4d1b9ce51ed00c6666dd6bb87fc06
BLAKE2b-256 af0268376e71a48c6b01074e64c6aea7be92b2ba824fa30ad5efcd515534f2e2

See more details on using hashes here.

File details

Details for the file irods_avu_json-2.2.0-py3-none-any.whl.

File metadata

  • Download URL: irods_avu_json-2.2.0-py3-none-any.whl
  • Upload date:
  • Size: 23.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.52.0 CPython/3.8.6

File hashes

Hashes for irods_avu_json-2.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a63615c92e55b9cce38554f9399fcf46aaae0ad755105173ed7b48754de0da6e
MD5 95d6dafa417b4b58e6b0ad618dd9e0db
BLAKE2b-256 a03f381094f0bb2833b1cfe0f66bba996ff5bd45d173043f20bd851f2fdd79b6

See more details on using hashes here.

Supported by

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