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,
inputis either:- a json-serializable
str, or - a json-serializable
dict
- a json-serializable
changesetis a json-serializablestrordict, or ajson_updater.ChangeSetobject.- a json-serializable
strconforming to thejson_updater.ChangeSet, - a json-serializable
dictconforming to thejson_updater.ChangeSet, or - a
json_updater.ChangeSetobject
- a json-serializable
ChangeSet Spec
The ChangeSet definition can be found here; it consists of a set of Change objects. Each Change contains:
- an
op(operation), - a
pathwhich conforms to jsonpath syntax, - an optional
valueparameter, used in certainoptypes - an optional
indexparameter, used in certainoptypes
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5bd2bf9799a6b003477b58ec55540f979ae06adacc6de6308c947aff183ad0e2
|
|
| MD5 |
058b2e3dcbd108ecdca68e8304356490
|
|
| BLAKE2b-256 |
981129caf1bd757b508ff5c925309ca599f24d8314deefd73603c387eb5cad41
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c377197873ed0829a02c51c7460d0eb6ed84d5193f037dff987845bbd3eecf2b
|
|
| MD5 |
d4177743bc12fea723135fee63af6976
|
|
| BLAKE2b-256 |
1d78891769e2832dbc87b7dbf2cfe201f866e2d2d6dcf9ac13e7e1dd72ec5c7f
|