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
Close
Hashes for get_nested_value_by_path-0.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac99ff584c1461e27543a66e52d95aaf75cbe31abcdb7305b1a449bcfd768631 |
|
MD5 | 9a6b99446423defecd65f817ee6086db |
|
BLAKE2b-256 | d27dc28af8add6e9861f5cfad3774ca4322cdd63cec43147b7ca0c78c75deba9 |
Close
Hashes for get_nested_value_by_path-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 534c9b100746b1b5b714a93a9acf052d47ddf35d1e766a40da005d5bbdad77ab |
|
MD5 | ff4de45b5bcb5a645bf147911b18d55c |
|
BLAKE2b-256 | 717536faa5e90bd90429683759e4ed3409b2c85fbe2f7845c38b065516d179d6 |