New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

pyjsonedit

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pyjsonedit

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

  • 1.0.4
  • PyPI
  • Socket score

Maintainers
1

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:

selectoractionnode typecomments
*select all items in current node-
[n]select n-th item of curent nodearray
{n}select n-th item of curent nodeobject
keyselect node chilld by nameobject
"key"select node chilld by nameobject
>mark current node as seleced-
a=bcheck if current node has child 'a' with value 'b'object
:beforeadd text before selected node-must at end of pattern
:afteradd text after selected node-must at end of pattern

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]...

  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}

string_match_mark

project stats

string_match_mark

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc