Skip to main content

A library to operate on JSON objects

Project description

json-operator is a tool which provides operations on JSON data.

If a JSON object is regarded as a data set (key-value pair), we can apply set operations on it. An example is to find out all the common attributes in two JSON objects. Another example is to check if two JSON objects are equal or not.

Currently json-operator supports 4 operations: equal, intersection, union, subtract.

Installation

$ pip install json-operator

Embedded examples

json-operator can be embedded into your program as a library.

import json_operator as jo
import json

# construct JSON objects
obj1 = json.loads('{"a": 1, "b":2}')
obj2 = json.loads('{"a": 1, "c":"3"}')

# equal operation
res = jo.equal(obj1, obj2)           # False

# intersection
res = jo.intersection(obj1, obj2)    # {"a":1}

# union
res = jo.union(obj1, obj2)           # {"a":1, "b":2, "c":"3"}

# subtract
res = jo.subtract(obj1, obj2)        # {"b":2}

res = jo.subtract(obj2, obj1)        # {"c":"3"}

Standalone usage

$ json-operator --help

usage: json-operator [--lt LT] [--rt RT] [--lf LF] [--rf RF] [--out OUT] [--help] [operator]

command utility to operate on JSON objects. Supported operators: equal, intersection, subtract, union.

positional arguments:
  operator   action command

optional arguments:
  --lt LT    left-side JSON text. Overwrite --lf option
  --rt RT    right-side JSON text. Overwrite --rf option
  --lf LF    left-side file where JSON is stored
  --rf RF    right-side file where JSON is stored
  --out OUT  output file. Default is stdout
  --help     print this help message

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

json-operator-0.0.5.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

json_operator-0.0.5-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file json-operator-0.0.5.tar.gz.

File metadata

  • Download URL: json-operator-0.0.5.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.0

File hashes

Hashes for json-operator-0.0.5.tar.gz
Algorithm Hash digest
SHA256 6c2f52c53c404ec1cf67027801014e94cae38b7fde9fd22dfdfbe59b9f3f3ddb
MD5 9964618b835bc0f60cca4df1bd26a3e5
BLAKE2b-256 dda48f49939be46a841f5a99c2cf4a569e8bc88450d2d8bf74357c5b93452db7

See more details on using hashes here.

File details

Details for the file json_operator-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: json_operator-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.0

File hashes

Hashes for json_operator-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 812c217fec3b25b6f0b8da4b653ca16bd33f116a9974a87aea18c02e05f2b209
MD5 867c9c22c4cf105d7daa11086f53384b
BLAKE2b-256 1d65a3316987d38e7a14bab5c858d2413716a585758f4f1e83d96e227285aec3

See more details on using hashes here.

Supported by

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