Skip to main content

jsonkeysearch: Searches for keys in JSON format files.

Project description

jsonkeysearch

Description

jsonkeysearch is a Python library that recursively searches for keys in JSON format files.

Installaction

Usage

from jsonkeysearch import JSONKeySearch

# https://json.org/example.html
json_example = {
    "menu": {
        "id": "file",
        "value": "File",
        "popup": {
            "menuitem": [
                {"value": "New", "onclick": "CreateNewDoc()"},
                {"value": "Open", "onclick": "OpenDoc()"},
                {"value": "Close", "onclick": "CloseDoc()"},
            ]
        },
    }
}


target = JSONKeySearch(json_example)

# [1] Append all dictionary with onclick as key in a list
key_ = "onclick"
value_ = "" # All value in key
target.search(key=key_, value=value_)

print(target.jsonObject)
# [
#     {"value": "New", "onclick": "CreateNewDoc()"},
#     {"value": "Open", "onclick": "OpenDoc()"},
#     {"value": "Close", "onclick": "CloseDoc()"},
# ]

# [2] Append dictionary in a list with onclick as key and 'Open' as value
key_="onclick"
value_ = "Open"
target.search(key = key_, value = value_)

print(target.jsonObject)
# [{"value": "Open", "onclick": "OpenDoc()"}]

for dict_ in target.jsonObject:
    print(dict_[key_])
# 'OpenDoc()'

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

jsonkeysearch-0.1.1.tar.gz (4.5 kB view hashes)

Uploaded Source

Built Distribution

jsonkeysearch-0.1.1-py3-none-any.whl (4.9 kB view hashes)

Uploaded Python 3

Supported by

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