dictionary={' items': { 'heading': 'Maps','description':'Maps123','imagepath':/music/images/','config':{'config1':12,'config2':123}},'db':{'username':'xyz','password':'xyz'},'version':'v1'}
I want the output in the format:
items/heading: Maps
items/description: Maps123
items/image_path: /music/images/v2/web_api-music.png
items/config/config1: abcd
items/config/config2: hello
db/username: xyz
db/password: xyz
version: v1
>Solution :
Check it :
def flatten(x, parent=''):
for key in list(x.keys()):
if( type(x[key]) is dict ):
flatten(x[key], parent+'/'+str(key))
else:
print(parent+'/'+str(key)+': ' + str(x[key]))
dictionary={'items': { 'heading': 'Maps','description':'Maps123','imagepath':'/music/images/','config':{'config1':12,'config2':123}},'db':{'username':'xyz','password':'xyz'},'version':'v1'}
flatten(dictionary)