Skip to main content

Searching Python Dictionaries/JSON files.

Project description

dictpy (Dictionary Python)

tests tests tests downloads license

This Python Package can help with finding data in large complex Python dictionaries. These data structures of typical of JSON Files.

Installation

pip install dictpy

Usage

Load in a JSON file.

import json

with open(data_path, "r") as f:
    text = f.read()
    json_data = json.loads(text)

Preform search. It will find all valid objects in the search. Use .result to view results.

import dictpy

search = DictSearch(data=json_data, target=target)
print(search.result)
    

Example return object: The return object is a list[list[tree, obj]].

tree shows the navigation to get to the data ('.' separated)

obj shows the object found

[['Record.Section.TOCHeading', {'TOCHeading': 'Chemical Safety'}],
 ['Record.Section.Information.Name', {'Name': 'Chemical Safety'}]]

How to format target

You can exact match on strings, int, floats and single line dictionaries. Examples:

{"RecordType": "CID"}
{"RecordNumber": 6}
{"TOCHeading": "Structures"}
2526
"3D Conformer"

You also can do partial dictionary searches with "*" as a wild card.

{"MoveToTop": "*"}
{"*": "Chemical Safety"}

Options of what is returned

Currently, there are two return options. The exact object (default) or parent object. To change to parent object, change return function:

search = DictSearch(data=json_data, target=target, return_func=DictSearch.return_parent_object)    

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

dictpy-0.0.2.tar.gz (4.7 kB view hashes)

Uploaded Source

Built Distribution

dictpy-0.0.2-py3-none-any.whl (4.7 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