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 | comments |
|---|---|---|---|
| * | 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 | - | |
| a=b | check if current node has child 'a' with value 'b' | object | |
| :before | add text before selected node | - | must at end of pattern |
| :after | add text after selected node | - | must at end of pattern |
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]...
Select and mask parts of json
Options:
--symbol TEXT
-i, --insert save changes to file
--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]...
select and modify parts of json
Options:
-i, --insert save changes to file
--help Show this message and exit.
example 1: simple string
pyjsonedit-modify "pass" 'P@$W&$d' "{'pass':123}"
{'pass':P@$W&$d}
example 2: python code:
file /home/dave/somefile.py
#!/usr/bin/python3
def modify(node,ctx):
return "'<"+str(1)+">'"
node - matched node
ctx - context in witch node was matched: file_name & match_nr
pyjsonedit-modify "*" /home/dave/somefile.py "{'a':1}"
{'a':'<1>'}
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
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 pyJsonEdit-1.0.4.tar.gz.
File metadata
- Download URL: pyJsonEdit-1.0.4.tar.gz
- Upload date:
- Size: 11.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c4c6520862b1c655dea22507e7b4e23ad34b6250694f2f9c4a6c15d07d12ff2
|
|
| MD5 |
9ff78e4059797338a43b9831aedd4c01
|
|
| BLAKE2b-256 |
7b560028b753a9080fa8820b9c032327599b75f8550e8b6e758d0010711108ed
|
File details
Details for the file pyJsonEdit-1.0.4-py3-none-any.whl.
File metadata
- Download URL: pyJsonEdit-1.0.4-py3-none-any.whl
- Upload date:
- Size: 12.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0c57d079c8e45afe9b0bcfa3e1fe0d3223eb9c9c5cdc5218838510cffb412ebb
|
|
| MD5 |
976edbb7e3c08efc23b12ee4885178c9
|
|
| BLAKE2b-256 |
4a39985c67e0c3388fcde10f3f3c2aa40c0b5c35e643a598ce23ddf102b0f386
|