JsonSearch is a simple, yet effcient python library for searhing specific elements in json data.
Project description
JsonSearch
JsonSearch is a simple, yet effcient python library for searhing specific elements in json data.
>>> from jsonsearch import JsonSearch
>>> test_data = {
... "store": {
... "book": [
... {
... "category": "reference",
... "author": "Nigel Rees",
... "title": "Sayings of the Century",
... "price": 8.95
... },
... {
... "category": "fiction",
... "author": "Evelyn Waugh",
... "title": "Sword of Honour",
... "price": 12.99
... },
... {
... "category": "fiction",
... "author": "Herman Melville",
... "title": "Moby Dick",
... "isbn": "0-553-21311-3",
... "price": 8.99
... },
... {
... "category": "fiction",
... "author": "J. R. R. Tolkien",
... "title": "The Lord of the Rings",
... "isbn": "0-395-19395-8",
... "price": 22.99
... }
... ],
... "bicycle": {
... "color": "red",
... "price": 19.95
... }
... },
... "expensive": 10
... }
>>> jsondata = JsonSearch(object=test_data, mode='j')
>>> jsondata.search_all_value(key='title')
['Sayings of the Century', 'Sword of Honour', 'Moby Dick', 'The Lord of the Rings']
>>> jsondata.search_all_path(key='title')
[['store', 'book', 0, 'title'], ['store', 'book', 1, 'title'], ['store', 'book', 2, 'title'], ['store', 'book', 3, 'title']]
>>> jsondata.search_first_value(key='title')
'Sayings of the Century'
>>> jsondata.search_first_path(key='title')
['store', 'book', 0, 'title']
When json data have nested objects, JsonSearch allows you to find specific elements in json data easily.
Take the program above as an example, if you want to get the first 'title'
value in data, you don't need to use test_data['store']['book'][0]['title']
anymore, you can just use jsondata.search_first_value(key='title')
.
Install
JsonSearch is available on PyPI:
pip install jsonsearch
or
pip install --index-url https://pypi.org/simple/ jsonsearch
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
jsonsearch-0.0.2.tar.gz
(15.6 kB
view hashes)
Built Distribution
jsonsearch-0.0.2-py3-none-any.whl
(15.6 kB
view hashes)
Close
Hashes for jsonsearch-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c04369acfd7d51bfd65e0647f56c81fbfce2ab501ff98bc4e98b696be0e711a |
|
MD5 | 4dfb93955c68286004108afe9c663a92 |
|
BLAKE2b-256 | 1f91b5a47df8c9ba5fa4be7c850435231d347cba3fc1a6320ca6c079aa511759 |