Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
A library to manage JSONs with encoded JSON more effectively (e.g. AWS Event Bridge Events, AWS API Gateway Events)
A library to manage JSONs with encoded JSON more effectively (e.g. AWS Event Bridge Events, AWS API Gateway Events)
pip install nested_json
import nested_json as njson
The main API of the library consist of:
Nested(obj)
- to convert any list or dictionary to a nested oneparse(str)
- to parse a JSON string to a nested JSONprocess(obj)
- to process/stringify any nested JSONdumps(obj)
, dump(obj, fp)
- same as from the json
module, but supports nested JSONloads(str)
, load(fp)
- same as from the json
module, but supports nested JSONdict
/ list
as nestedThe Nested
function can be used to mark a dictionary or
list as nested data, which will add a particular property to it,
marking it nested. This property was later removed during processing.
data = {
"id": "12345",
"event": {
"payload": {
"rawpayload": njson.Nested({
"key": "value",
"other": 2,
"foo": True
}),
"tags": njson.Nested([
"hello",
"world
])
}
}
}
# {
# "id": "12345",
# "event": {
# "payload": {
# "rawpayload": {
# "__nested__": True,
# "key": "value",
# "other": 2,
# "foo": True
# },
# "tags": [
# "__nested__",
# "hello",
# "world
# ]
# }
# }
# }
Using the process
function, the nested keys can be removed
and nested data converted to JSON string.
processed_data = njson.process(data)
# {
# "id": "12345",
# "event": {
# "payload": {
# "rawpayload": "{\"key\": \"value\", \"other\": 2, \"foo\": true}",
# "tags": "[\"hello\", \"world\"]"
# }
# }
# }
The result of process
can be already passed to json.dumps
,
but the njson.dumps
can also be used with nested JSON data.
json_string = njson.dumps(data)
# '{"id": "12345", "event": {"payload": {"rawpayload": "{\\"key\\": \\"value\\", \\"other\\": 2, \\"foo\\": true}", "tags": "[\\"hello\\", \\"world\\"]"}}}'
Nested JSON string can be parsed to nested JSON data with the loads
function or the parse
function
assert njson.loads(json_string) == data
assert njson.parse(processed_data) == data
assert njson.parse(json.loads(json_string)) == data
Note that both loads
and dumps
use the json.loads
and json.dumps
functions; thus they can be used with "normal" JSON as well.
FAQs
A library to manage JSONs with encoded JSON more effectively (e.g. AWS Event Bridge Events, AWS API Gateway Events)
We found that nested-json 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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.