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 doint 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 | - |
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 and 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
$ pyjsonedit --help
Usage: pyjsonedit [OPTIONS] PATTERN JSON
cli method for masking matching parts of json
Options:
--symbol TEXT
--color enable color output
--help Show this message and exit.
example: mask multiple nodes
$ pyjsonedit "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 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-0.0.15.tar.gz
(6.3 kB
view hashes)
Built Distribution
Close
Hashes for pyJsonEdit-0.0.15-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68a04b89e410d73263eb5a73d1f5653ccc49f8c5d9cc86c1efcea2172beea4c1 |
|
MD5 | f8d40c0af2f30e4777ecf630ef0f2b03 |
|
BLAKE2b-256 | ad57bc4c87519210da1cb9d9c4557af09a3db7afa7c9f72130e7a131763e11e6 |