This is my JSON data. JSON data consists of some properties but I only need command and subcommands properties.
{
command: 'abc',
depth: 1,
help: '...',
subcommands:[
{
command: 'abc folder',
depth: 2,
help: '...',
subcommands:[
{
command: 'abc folder add',
depth: 3,
help: '...',
subcommands:[
{
command: 'abc folder add id',
depth: 4,
help: '...',
subcommands: []
},
{
command: 'abc folder add type',
depth: 4,
help: '...',
subcommands: []
},
{
command: 'abc folder add name',
depth: 4,
help: '...',
subcommands: []
}]
}],
{
command: 'abc folder list',
depth: 3,
help: '...',
subcommands: []
},
{
command: 'abc folder view',
depth: 3,
help: '...',
subcommands: [
{
command: 'abc folder view id',
depth: 4,
help: '...',
subcommands: []
},
{
command: 'abc folder view type',
depth: 4,
help: '...',
subcommands: []
},
{
command: 'abc folder view name',
depth: 4,
help: '...',
subcommands: []
}
}]
}]
}
Nested dictionary I'd like to retrieve from the JSON data is following:
{
'abc':
{
'folder':
{
'add':
{
'id': {},
'type': {},
'name': {}
},
'list': {},
'view':
{
'id': {},
'type': {},
'name': {}
}
}
}
}
I need to use recursive function so that it will work for deeper properties. It only needs to use command and subcommands. If there's subcommands has empty value then in result, related property's value should also be empty. Please post your suggestion that effectively makes a nested python dictionary.
All your answers will be appreciated. Thanks.