I have tho following json file:
{
"layout": {
"user": {
"pages": {
"Home": { // first page
"sub_domain_name": "demo",
"title": "Home",
"page_id": 111111,
"desktop": [ // first node in first page
{
"grid_name": "row",
"component_id": "31fac419-f1ff-4614",
"main_classes": "border border-primary",
"items": [ // first node in desktop
{
"grid_name": "col",
"component_id": "111111",
"component_name": "Card",
"items": []
}
]
},
{
"grid_name": "row",
"component_id": "222222",
"main_classes": "border-top-0",
"items": [
{
"grid_name": "col",
"component_id": "3333",
"component_name": "Author",
"items": []
}
]
},
]
}
"section": [
"s11"
],
"mobile": [ //second node in first page
{
"grid_name": "row",
"component_id": "4444",
"main_classes": "border",
"items": [ // first node in mobile
{
"grid_name": "col",
"component_id": "5555",
"component_name": "Card",
"items": []
}
]
},
{
"grid_name": "row",
"component_id": "888",
"main_classes": "border-top-0 ",
"items": [
"grid_name": "col",
"component_id": "999"
"component_name": "Card",
"items": []
},
{
"grid_name": "col",
"component_id": "11",
"component_name": "Media",
"items": []
}
]
}
]
}
]
},
"contact": { // second page
"sub_domain_name": "demo3",
"title": "contact",
"page_id": 2222222,
"desktop": [ // first node in second page
{
"grid_name": "row",
"component_id": "22",
"component_name": "Table",
"items": []
},
{
"grid_name": "row",
"component_id": "99",
"component_name": "Table",
}
}
],
"section": [
"s4"
],
"mobile": [ // second node in second page
{
"grid_name": "row",
"component_id": "67",
"component_name": "Component",
"items": []
},
{
"grid_name": "row",
"component_id": "0000",
"component_name": "Table",
}
]
}
I want to print all component_name
from this json file using python. Not shure what the problem is tho. Does anyone see the problem?
import json
myJsonFile=open("config-2_new.json")
jsondata=myJsonFile.read()
obj=json.loads(jsondata)
dict_process=obj['layout']
for i in dict_process:
inner_page=dict_process[i]['pages']
pages_list=inner_page.keys()
for j in pages_list:
desktop=inner_page[j]['desktop']
for x in range(0,len(desktop)):
child_keys=desktop[x]['child']
for k in child_keys:
print (k['component_name'])
Thanks for any answers allready.