Turns nested dictionary keys to dotted strings with their corresponding values into a basic dictionary
Project description
dict_dot_notate
dict_dot_notate turns nested dictionary keys to dotted strings with their corresponding values into a basic dictionary.
Installation
pip install dict-dot-notate
Usage
from dot_notate.dot import dict_dot_notate
Example
data = {
"obj": "obj",
"nested_once": {"first": "first"},
"nested_twice": {
"twice": {"inner_nest": {"second": "second"}}
},
"nested_thrice": {
"thrice": {"second_nest": {"tripple_nest": {"tripple": "thrice"}, "three": "three"}}
}
}
call the relevant method to convert our dict
result = dict_dot_notate(data)
output
{
'obj': 'obj',
'nested_once.first': 'first',
'nested_twice.twice.inner_nest.second': 'second',
'nested_thrice.thrice.second_nest.tripple_nest.tripple': 'thrice',
'nested_thrice.thrice.second_nest.three': 'three'
}
If a dict passed in has a list value, Then the output will be as below
Example
data = {
"obj": "obj",
"nested_once": {"first": "first"},
"nested_twice": {
"twice": {"inner_nest": [1, 2, 3, 4, 5]}
}
}
conversion
result = dict_dot_notate(data)
output
{
'obj': 'obj',
'nested_once.first': 'first',
'nested_twice.twice.inner_nest': [1, 2, 3, 4, 5]
}
Don't pass in a list of dictionaries.
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
dict-dot-notate-0.0.3.tar.gz
(2.1 kB
view hashes)
Built Distribution
Close
Hashes for dict_dot_notate-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1da0de5611aaabbdc3535d0f053cb1e5cf396c54941993815b3c085073c37a9d |
|
MD5 | da4f3ef3a656597b0e3e401cc2fc8d94 |
|
BLAKE2b-256 | 839e046d6b801207654029482ec4ad806df0a59bab565538f3972ff4d715f6a0 |