Skip to main content

Search nested lists and dicts

Project description

Osearch - The tool for finding information in nested dicts/lists

When you are working with imported JSON in python, it's often hard to get an overview of the datastructure. I created osearch to help you with this. It allows you to search for strings or integers in huge nested structures. Here is an example of a messy test structure:

tstObj = [
    1,
    2,
    3,
    "listval2",
    "listval5",
    {
        "dict1": "dictval1",
        "dict2": "dictval2",
        "dict3": 3,
        "dict4": ["item1", "A long string here", 1000, "another string"],
        100: 222,
    },
]

first we import the osearch lib:

from osearch import osearch

Now we can do some funny searches for strings containing the part "val":

>> osearch(tstObj, "val", method="contains", prettyprint=True)
[3]='listval2'
[4]='listval5'
[5]['dict1']='dictval1'
[5]['dict2']='dictval2'

Or we could search for an integer:

>> osearch(tstObj, 100, prettyprint=True)
[5][100]

Or maybe even a regular expression search that is non-case sensitive. Here we search for all occurances of keys/values that ends in val1 or val5:

>> osearch(tstObj, r"val[15]$", method="regex-case", prettyprint=True)
[4]='listval5'
[5]['dict1']='dictval1'

Have fun

/ Alex Skov Jensen

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

osearch-0.1.0.tar.gz (3.7 kB view details)

Uploaded Source

File details

Details for the file osearch-0.1.0.tar.gz.

File metadata

  • Download URL: osearch-0.1.0.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.0.post20200616 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

File hashes

Hashes for osearch-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5a2846923ffcab6b40a5d0ebdf25700a18cdddb731ec9a080e49857c071297d8
MD5 4480be0946a8f944003ca3ce12045efb
BLAKE2b-256 2bcb11edbc7173521a0818a608c6a62850dbed6111d10946e48fe7bae9b490f5

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