Skip to main content

get_nested_value_by_path

Get a nested value of nested dict by path

def get_nested_value_by_path(nested_dict, path, default=None, mode='mix'):
"""
:param nested_dict: nested dict object
    {
      "club": [
        {
          "manager": {
            "last_name": "Lionel",
            "first_name": "Messi"
          }
        }
      ]
    }
:param path: path to access the nested dict value
    "club/0/manager/first_name"
:param default: default value
:param mode: ['json', 'list', 'mix']
:return: value of nested dict
    "Messi"
"""

#####Installation: https://pypi.org/project/get-nested-value-by-path/

pip install get-nested-value-by-path

#####Usage:

nested_dict = {
  "key": [
    {
      "sub_key": {
        "sub_sub_key_1": "Value_1",
        "sub_sub_key_2": "Value_2"
      }
    }
  ]
}

before:

sub_sub_value_1 = nested_dict['key'][0]['sub_key']['sub_sub_key_1']

after:

from get_nested_value_by_path import get_nested_value_by_path
sub_sub_value_1 = get_nested_value_by_path(nested_dict, "key/0/sub_key/sub_sub_key_1")

#####Example:

nested_dict = {
  "club": [
    {
      "manager": {
        "last_name": "Lionel",
        "first_name": "Messi"
      }
    }
  ]
}

before:

manager_last_name = nested_dict['club'][0]['manager']['last_name']

after:

from get_nested_value_by_path import get_nested_value_by_path
manager_last_name = get_nested_value_by_path(nested_dict, "club/0/manager/last_name")

Release files for get-nested-value-by-path 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for get-nested-value-by-path 0.1.1
File Size Uploaded
get_nested_value_by_path-0.1.1.tar.gz 1.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for get-nested-value-by-path 0.1.1
File Interpreter ABI Platform
get_nested_value_by_path-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 5.1 kB

Release files / get_nested_value_by_path-0.1.1.tar.gz

Download URL get_nested_value_by_path-0.1.1.tar.gz
Size 1.9 kB
Tags Source
SHA-256 checksum
How to use checksums
ac99ff584c1461e27543a66e52d95aaf75cbe31abcdb7305b1a449bcfd768631
BLAKE2b-256 checksum
How to use checksums
d27dc28af8add6e9861f5cfad3774ca4322cdd63cec43147b7ca0c78c75deba9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.6.9

Release files / get_nested_value_by_path-0.1.1-py3-none-any.whl

Download URL get_nested_value_by_path-0.1.1-py3-none-any.whl
Size 3.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
534c9b100746b1b5b714a93a9acf052d47ddf35d1e766a40da005d5bbdad77ab
BLAKE2b-256 checksum
How to use checksums
717536faa5e90bd90429683759e4ed3409b2c85fbe2f7845c38b065516d179d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.6.9

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page