Get a nested value of nested dict by path
Project description
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")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file get_nested_value_by_path-0.1.1.tar.gz
.
File metadata
- Download URL: get_nested_value_by_path-0.1.1.tar.gz
- Upload date:
- Size: 1.9 kB
- Tags: Source
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac99ff584c1461e27543a66e52d95aaf75cbe31abcdb7305b1a449bcfd768631 |
|
MD5 | 9a6b99446423defecd65f817ee6086db |
|
BLAKE2b-256 | d27dc28af8add6e9861f5cfad3774ca4322cdd63cec43147b7ca0c78c75deba9 |
File details
Details for the file get_nested_value_by_path-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: get_nested_value_by_path-0.1.1-py3-none-any.whl
- Upload date:
- Size: 3.2 kB
- Tags: Python 3
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 534c9b100746b1b5b714a93a9acf052d47ddf35d1e766a40da005d5bbdad77ab |
|
MD5 | ff4de45b5bcb5a645bf147911b18d55c |
|
BLAKE2b-256 | 717536faa5e90bd90429683759e4ed3409b2c85fbe2f7845c38b065516d179d6 |