Search through JSON data key:values by key(s)
Project description
jsonparse
jsonparse is a simple JSON parsing library. Extract the values from key:value pairs providing the key(s).
Install
pip install jsonparse
Usage
from jsonparse import Parser
parse = Parser(stack_trace=False, queue_trace=False)
data = [
{"key": 1},
{"key": 2},
{"my":
{"key":
{"chain":"A"}
}
},
{"your":
{"key":
{"chain":"B"}
}
}
]
print(parse.key(data, 'key'))
[{'chain': 'B'}, {'chain': 'A'}, 2, 1]
print(parse.key(data, 'chain'))
['B', 'A']
print(parse.key_chain(data, ['my', 'key', 'chain']))
['A']
print(parse.key_chain(data, ['key']))
[1, 2]
print(parse.key_chain(data, ['*', 'key', 'chain']))
['A', 'B']
print(parse.key_chain(data, ['*', 'key', '*']))
['A', 'B']
API
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.
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.
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.6.0.tar.gz
(4.8 kB
view hashes)
Built Distribution
Close
Hashes for jsonparse-0.6.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b5ad6e278c5f483889949999b7ba0ab7b753f28cf56626e4ab24b82dc2b5b760 |
|
MD5 | 7d74f8578b58ac76e664b03cf49a4e7e |
|
BLAKE2b-256 | da90625bb92c6482ba13507158f67fcedf861bb79308b7ef71d967bb2ebf7be7 |