Searching Python Dictionaries/JSON files.
Project description
dictpy (Dictionary Python)
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.