Skip to main content

Turns nested dictionary keys to dotted strings with their corresponding values into a basic dictionary

Project description

Build Status Coverage Status

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for dict-dot-notate, version 0.0.2
Filename, size File type Python version Upload date Hashes
Filename, size dict_dot_notate-0.0.2-py3-none-any.whl (3.4 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size dict-dot-notate-0.0.2.tar.gz (2.0 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page