Edit parts of json strings & files while keeping the orginal, inconsistent formating
Project description
pyJsonEdit
Edit parts of inconsistently formatted json.
It's just a bit slower that doing this by hand!
matcher
Now you can easly select nodes in json tree
syntax:
selector | action | node type |
---|---|---|
* | select all items in current node | - |
[n] | select n-th item of curent node | array |
{n} | select n-th item of curent node | object |
key | select node chilld by name | object |
"key" | select node chilld by name | object |
> | mark current node as seleced | f- |
a=b | check if current node has child 'a' with value 'b' | object |
example 1:
key > [0]
this pattern will match one element by:
- selecting "key" element in root node (assuring that is an object)
- select first element in it (assumintg its an array)
example 2:
name > *
this pattern will match multiple elements by:
- selecting "name" element in root node (assuring that is an object)
- select all element in it
how to install
pip install --upgrade pyjsonedit
python module
import pyjsonedit
comand line - mark
$ pyjsonedit-mask --help
Usage: pyjsonedit-mask [OPTIONS] PATTERN [JSONS]...
cli method for masking matching parts of json
Options:
--symbol TEXT
--color enable color output
--help Show this message and exit.
example:
pyjsonedit-mask "pass" "{'pass':123}"
{'pass':XXX}
comand line - modify
$ pyjsonedit-modify --help
Usage: pyjsonedit-modify [OPTIONS] PATTERN TEMPLATE [JSONS]...
cli method for masking matching parts of json
Options:
--insert don't print save to file
--help Show this message and exit.
example:
pyjsonedit-modify "pass" 'P@$W&$d' "{'pass':123}"
{'pass':P@$W&$d}
example: mask multiple nodes
$ pyjsonedit-mask **"quiz > * > q1 >*"** DOC/example.json
{
"quiz": {
"sport": {
"q1": {
"question": XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX,
"options": XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX,
"answer": XXXXXXXXXXXXXXX
}
},
"maths": {
"q1": {
"question": XXXXXXXXXXX,
"options": XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX,
"answer": XXXX
},
"q2": {
"question": "12 - 8 = ?",
"options": [
"1",
"2",
"3",
"4"
],
"answer": "4"
}
}
}
}
example: mask selected nodes
$ import pyjsonedit
$ pyjsonedit.string_match_mark("{'pass':123}","pass")
{'pass':XXX}
project stats
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
pyJsonEdit-1.0.1.tar.gz
(10.3 kB
view details)
Built Distribution
File details
Details for the file pyJsonEdit-1.0.1.tar.gz
.
File metadata
- Download URL: pyJsonEdit-1.0.1.tar.gz
- Upload date:
- Size: 10.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d86d4c81a6cb272e1ad7818280d10267ef419892eaf4440676ff15dc11cb825 |
|
MD5 | c64e0098e2170cd13610142acad4c72e |
|
BLAKE2b-256 | 286b4ccf5504abb4768753aac4be3cafa1e8a3e444408a9f764da732f41ba0fb |
Provenance
File details
Details for the file pyJsonEdit-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: pyJsonEdit-1.0.1-py3-none-any.whl
- Upload date:
- Size: 11.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 46bd1b09ad7c527558bdce5843220297d0a56bdb8cfe01b1115757ae2102930f |
|
MD5 | 6710b2a47a87b4774d89c2806aae06dd |
|
BLAKE2b-256 | 9b7a99e4c088b7da4cb34b1cfaeec758545e225ae4350b64478150d4acf8672e |