Skip to main content

Updates JSON according to a change spec

Project description

json-updater

Setup

To import this library to your environment:

  • pip install json-updater

To import this function in your python code:

  • from json_updater import update_json

Use

To invoke:

  • modified_input = update_json(input, changeset)

Where,

  • input is either:
    • a json-serializable str, or
    • a json-serializable dict
  • changeset is a json-serializable str or dict , or a json_updater.ChangeSet object.
    • a json-serializable str conforming to the json_updater.ChangeSet,
    • a json-serializable dict conforming to the json_updater.ChangeSet, or
    • a json_updater.ChangeSet object

ChangeSet Spec

The ChangeSet definition can be found here; it consists of a set of Change objects. Each Change contains:

  • an op (operation),
  • a path which conforms to jsonpath syntax,
  • an optional value parameter, used in certain op types
  • an optional index parameter, used in certain op types

Changes are applied in the order they are received.

Operation Types

The following operations are supported:

Delete: "del"

Deletes all json nodes specified in the change path

Init: "init"

For all json nodes specified in the change path, if that node doesn't exist, its value is initialized to the change value. Otherwise, ignores the existing node.
Primarily used to ensure an array exists in the object tree before invoking Array Insert commands.

Upsert: "ups"

For all json nodes specified in the change path, creates or replaces that node, setting the value to the change value

Replace: "rpl"

For all json nodes specified in the change path, replaces that node, setting the value to the change value

Array Insert: "arr_ins"

For all json nodes specified in the change path, which must be of type array, insert the change value at the provided index.
If index is null, appends to the end of the array.

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-updater-0.0.6.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

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

json_updater-0.0.6-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file json-updater-0.0.6.tar.gz.

File metadata

  • Download URL: json-updater-0.0.6.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for json-updater-0.0.6.tar.gz
Algorithm Hash digest
SHA256 5bd2bf9799a6b003477b58ec55540f979ae06adacc6de6308c947aff183ad0e2
MD5 058b2e3dcbd108ecdca68e8304356490
BLAKE2b-256 981129caf1bd757b508ff5c925309ca599f24d8314deefd73603c387eb5cad41

See more details on using hashes here.

File details

Details for the file json_updater-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: json_updater-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for json_updater-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 c377197873ed0829a02c51c7460d0eb6ed84d5193f037dff987845bbd3eecf2b
MD5 d4177743bc12fea723135fee63af6976
BLAKE2b-256 1d78891769e2832dbc87b7dbf2cfe201f866e2d2d6dcf9ac13e7e1dd72ec5c7f

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