Skip to main content

Edit parts of json strings & files while keeping the orginal, inconsistent formating

Project description

pyJsonEdit

PyPi version license tests

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:

  1. selecting "key" element in root node (assuring that is an object)
  2. select first element in it (assumintg its an array)

example 2:

name > *

this pattern will match multiple elements by:

  1. selecting "name" element in root node (assuring that is an object)
  2. 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:
  --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}

string_match_mark

project stats

string_match_mark

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

pyJsonEdit-0.0.24.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

pyJsonEdit-0.0.24-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file pyJsonEdit-0.0.24.tar.gz.

File metadata

  • Download URL: pyJsonEdit-0.0.24.tar.gz
  • Upload date:
  • Size: 9.1 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

Hashes for pyJsonEdit-0.0.24.tar.gz
Algorithm Hash digest
SHA256 47598af6fa6595f8da17340aaccca9595fe9fd5a16e61591a644a5204ae193c1
MD5 8c80a9f9a59cc581c51f74511b91bbdf
BLAKE2b-256 63806683fe799292fcb5786b655fb01c12fd8d71714c3e60e8dec82f9a1146c9

See more details on using hashes here.

Provenance

File details

Details for the file pyJsonEdit-0.0.24-py3-none-any.whl.

File metadata

  • Download URL: pyJsonEdit-0.0.24-py3-none-any.whl
  • Upload date:
  • Size: 9.7 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

Hashes for pyJsonEdit-0.0.24-py3-none-any.whl
Algorithm Hash digest
SHA256 041380bf756314082612f9ea619e82fa159d0fb05ae1cb9a6274dfc4b5a65378
MD5 ddcb014089cd8f1950dc6c62723a3f28
BLAKE2b-256 8595ef04a5e8d680be79d32433bfd52fcc72022bb5fbd766fd0ed1d610f767c2

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page