Security News
PyPI’s New Archival Feature Closes a Major Security Gap
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
jsonupdate-ng provides easy and scalable way to update any json document using following ways:
PS - jsonpath is a language like xpath to select single/multiple nodes from a given json. There are multiple tutorials on web to learn this.
Here are few resources to learn jsonpath:
jsonupdate-ng has following prerequisites:
jsonpath-ng>=1.4.3
setuptools>=39.1.0
you can install all the prerequisites either one by one or using the requirements.txt provided with source code:
pip install -r requirements.txt
RESTLibrary can be easily installed using pip with following command:
pip install jsonupdate-ng
Alternatively it can also be installed from the sourcecode:
python setup.py install
this python function takes two arguments, base json and head json, and updates the base json based on the details provided in head.
from jsonupdate_ng import jsonupdate_ng
updatedJson = jsonupdate_ng.updateJson(baseJson, headJson)
contents of base json
{
"page": 1,
"per_page": 6,
"total": 12,
"total_pages": 2,
"data": [
{
"id": 1,
"email": "george.bluth@reqres.in",
"first_name": "George",
"last_name": "Bluth",
"avatar": "https://reqres.in/img/faces/1-image.jpg"
},
{
"id": 2,
"email": "janet.weaver@reqres.in",
"first_name": "Janet",
"last_name": "Weaver",
"avatar": "https://reqres.in/img/faces/2-image.jpg"
},
{
"id": 3,
"email": "emma.wong@reqres.in",
"first_name": "Emma",
"last_name": "Wong",
"avatar": "https://reqres.in/img/faces/3-image.jpg"
},
{
"id": 4,
"email": "eve.holt@reqres.in",
"first_name": "Eve",
"last_name": "Holt",
"avatar": "https://reqres.in/img/faces/4-image.jpg"
},
{
"id": 5,
"email": "charles.morris@reqres.in",
"first_name": "Charles",
"last_name": "Morris",
"avatar": "https://reqres.in/img/faces/5-image.jpg"
},
{
"id": 6,
"email": "tracey.ramos@reqres.in",
"first_name": "Tracey",
"last_name": "Ramos",
"avatar": "https://reqres.in/img/faces/6-image.jpg"
}
]
}
contents of head json (comments are just to clarify the example, please remove them before trying it in your code)
{
"name" : "users", // this will add a name node at the root
"per_page" : 12, // this will update the per_page value
"company" : { "name" : "anything", "office" : "anywhere" }, // this will add a new object at the root
"total_pages" : "<<<DELETE>>>", // this will delete total_pages node from the root
"data" : [
{
"id": 100, // this will update id of the first item in the data list
"full_name": "deepak chourasia", // this will add a full_name node in the first item of the data list
}
],
"$.limit" : 6, // this will add a limit node at the root
"$.data[*].designation" : "developer", // this will add a designation node in all the objects inside data list
"$.data[?(@.id > 3)].salary" : "$100,000", // this will add a salary node in all the objects inside data list which have id > 3
"$.data[100]" : { // this can be used to add/update an object at provided index in the data list, if index is greater than current length of the list then item will be added to the end of the list
"id": 101,
"email": "deepak.chourasia@gmail.com",
"first_name": "Deepak",
"last_name": "Chourasia"
},
"$.data[?(@.id > 4 & @.id < 10)].avatar" : "<<<DELETE>>>" // this will delete avtar node from the object inside data list which has id > 4
}
this function checks if a node exists at given jsonpath in the provided json
from jsonupdate_ng import jsonupdate_ng
exists = jsonupdate_ng.checkIfNodeExistsAtGivenJsonPath(baseJson, "$.data")
this function can perform multiple tasks based on the situation:
from jsonupdate_ng import jsonupdate_ng
updatedJson = jsonupdate_ng.Add_Update_Delete_Node_AtGivenJsonPath(baseJson, "$.name", "Deepak Chourasia")
Creator and maintainer : Deepak Chourasia
JsonUpdate-NG is open source software provided under the Apache License 2.0
FAQs
A Next Generation Library to update any json document
We found that jsonupdate-ng demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
Research
Security News
Malicious npm package postcss-optimizer delivers BeaverTail malware, targeting developer systems; similarities to past campaigns suggest a North Korean connection.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.