Skip to main content

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


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 details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jsonsearch-0.0.2-py3-none-any.whl (15.6 kB view details)

Uploaded Python 3

File details

Details for the file jsonsearch-0.0.2.tar.gz.

File metadata

  • Download URL: jsonsearch-0.0.2.tar.gz
  • Upload date:
  • Size: 15.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.6.12

File hashes

Hashes for jsonsearch-0.0.2.tar.gz
Algorithm Hash digest
SHA256 f215e8fc7d5783e4d193f6e262b20976bd528572c10f498b81293eac2cb73fe2
MD5 64752f944ea28b43e97a888d21e2a522
BLAKE2b-256 92e3a57c360748a0ebc3a11ba256e5152280943db77d12b257d68b0f0b99b083

See more details on using hashes here.

File details

Details for the file jsonsearch-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: jsonsearch-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 15.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.6.12

File hashes

Hashes for jsonsearch-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0c04369acfd7d51bfd65e0647f56c81fbfce2ab501ff98bc4e98b696be0e711a
MD5 4dfb93955c68286004108afe9c663a92
BLAKE2b-256 1f91b5a47df8c9ba5fa4be7c850435231d347cba3fc1a6320ca6c079aa511759

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page