I have json object and mapper like below,
Json Object:
{
'App Builder': {
'ID': '1',
'children': [{
'API Builder': {
'ID': '2'
}
}, {
'UI': {
'ID': '3',
'children': [{
'UI Builder': {
'ID': '4'
}
}, {
'Template': {
'ID': '5',
'children': [{
'Angular': {
'ID': '6'
}
}, {
'React': {
'ID': '7'
}
}, {
'PHP': {
'ID': '8'
}
}]
}
}]
}
}]
}
}
Mapper:
{
'1': ['create an app', 'create app for me', 'can you create an application?'],
'2': ['create an app using API Buider', 'make an application using API Builder', 'create API Builder application'],
'3': ['create an app using user interface', 'make an application using UI', 'create UI application'],
'4': ['create an app using UI Buider', 'make an application using UI Builder', 'create UI Builder application'],
'5': ['create an app using Template', 'make an application using Template', 'create Template application'],
'6': ['create an app using Angular', 'make an application using Angular template', 'create Angular application'],
'7': ['create an app using React', 'make an application using React template', 'create React application'],
'8': ['create an app using PHP', 'make an application using PHP template', 'create PHP application']
}
Both object contains 'ID' using this I need to append values in original json object like below,
{
"App Builder": {
"ID": "1",
"1": ["create an app", "create app for me", "can you create an application?"],
"children": [{
"API Builder": {
"ID": "2",
"2": ["create an app using API Buider", "make an application using API Builder", "create API Builder application"]
}
}, {
"UI": {
"ID": "3",
"3": ["create an app using user interface", "make an application using UI", "create UI application"],
"children": [{
"UI Builder": {
"ID": "4",
"4": ["create an app using UI Buider", "make an application using UI Builder", "create UI Builder application"]
}
}, {
"Template": {
"ID": "5",
"5": ["create an app using Template", "make an application using Template", "create Template application"],
"children": [{
"Angular": {
"ID": "6",
"6": ["create an app using Angular", "make an application using Angular template", "create Angular application"]
}
}, {
"React": {
"ID": "7",
"7": ["create an app using React", "make an application using React template", "create React application"]
}
}, {
"PHP": {
"ID": "8",
"8": ["create an app using PHP", "make an application using PHP template", "create PHP application"]
}
}]
}
}]
}
}]
}
}
I tried to get path of my required json object using below.
json_path = {}
for intent in all_walks:
ep = []
temp = s
i=0
for val in intent.split('/'):
if i==0:
ep.append(val)
temp = temp[val]
else:
temp = temp['children']
ep.append('children')
for item in temp:
if val in item.keys():
ep.append(val)
temp = item[val]
i+=1
json_path[intent] = ep
print(json_path)
it gives me,
{'App Builder': ['App Builder'], 'App Builder/API Builder': ['App Builder', 'children', 'API Builder'], 'App Builder/UI': ['App Builder', 'children', 'UI'], 'App Builder/UI/UI Builder': ['App Builder', 'children', 'UI', 'children', 'UI Builder'], 'App Builder/UI/Template': ['App Builder', 'children', 'UI', 'children', 'Template'], 'App Builder/UI/Template/Angular': ['App Builder', 'children', 'UI', 'children', 'Template', 'children', 'Angular'], 'App Builder/UI/Template/React': ['App Builder', 'children', 'UI', 'children', 'Template', 'children', 'React'], 'App Builder/UI/Template/PHP': ['App Builder', 'children', 'UI', 'children', 'Template', 'children', 'PHP']}
Again I can't use this because children is an array.
How to solve this problem.
any help would be appreciable.