Search through JSON data key:values by key(s)
Project description
jsonparse
jsonparse is a simple JSON parsing library. Extract what's needed from key:value pairs.
Install
pip install jsonparse
Usage
from jsonparse import Parser
parser = Parser(stack_trace=False, queue_trace=False)
data = [
{"key": 1},
{"key": 2},
{"my":
{"key":
{
"chain": "A",
"rope": 5,
"string": 1.2,
"cable": False
}
}
},
{"your":
{"key":
{
"chain": "B"
}
}
}
]
parser.find_key(data, 'chain')
['B', 'A']
parser.find_key(data, 'key')
[{'chain': 'B'}, {'chain': 'A', 'rope': 5, 'string': 1.2, 'cable': False}, 2, 1]
parser.find_key_chain(data, ['my', 'key', 'chain'])
['A']
parser.find_key_chain(data, ['key'])
[1, 2]
parser.find_key_chain(data, ['*', 'key', 'chain'])
['A', 'B']
parser.find_key_chain(data, ['*', 'key', '*'])
['A', 5, 1.2, False, 'B']
parser.find_key_value(data, 'cable', False)
[{'chain': 'A', 'rope': 5, 'string': 1.2, 'cable': False}]
parser.find_key_value(data, 'chain', 'B')
[{'chain': 'B'}]
API
find_key(data: dict | list, key: str) -> list
- Provide JSON data as a dictionary or a list, as well as the key as a string
- Returns a list of values that match the corresponding key.
find_key_chain(data: dict | list, keys: list) -> list
-
Provide JSON data as a dictionary or a list, as well as a list of keys as strings.
-
Returns a list of values that match the corresponding key chain.
Wildcard '*' can be used as key(s) to match any.
find_key_value(data: dict | list, key: str, value: str | int | float | bool) -> list
- Provide JSON data as a dictionary or a list, a key as a string, and a value as a string, integer, float, or boolean.
- Returns a list of set(s) that contain the key:value pair.
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
jsonparse-0.8.0.tar.gz
(5.2 kB
view hashes)
Built Distribution
Close
Hashes for jsonparse-0.8.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9810238609888332e42c30634c00fb35b83e585570ae1b34625f4b8d87cf336c |
|
MD5 | 1cfe419aef7f1ef64abc247d1a4424f4 |
|
BLAKE2b-256 | 7fba1dd77bb1f8c87f08a691ca8bc40479cb8b675016fb99dbdc69cf9fcf8c61 |