Hi I need help to create a new list from looping through JSON output file "ruletree"
ruletree = { "account": "act_F-AC-1234", "contract": "ctr_F-1234", "propertyName": "www.domain.com", "rules": { "name": "default", "children": [ { "name": "Route One", "children": [], "behaviors": [ { "name": "origin", "options": { "originType": "CUSTOMER", "hostname": "first.gateway.com", }, } ], }, { "name": "Route Two", "children": [], "behaviors": [ { "name": "origin", "options": { "originType": "CUSTOMER", "hostname": "second.gateway.com", }, } ], }, ], }, } my code looks like this, getting error "TypeError: list indices must be integers or slices, not str"
hostnames = [] for host in ruletree['rules']['children']['behaviors']['options']: options.get('hostname', N/A) hostnames.append(host) print(hostnames) expected output
{"propertyName": "www.domain.com", "hostnames": "first.gateway.com, second.gateway.com"}