I have a JSON structure mentioned below and i am not sure how to traverse lower down in the hierarchy:
"json": { "count": 5, "next": null, "previous": null, "results": [ { "action": "pass", "application_groups": [], "applications": [], "created": "2024-06-20T09:53:20.139779+02:00", "custom_fields": {}, "description": "", "destination_address_groups": [], "destination_addresses": [], "destination_service_groups": [], "destination_services": [ { "created": "2024-06-18T02:00:00+02:00", "custom_fields": {}, "description": "", "display": "ICMP (ICMP)", "id": "c52f9be9-b4ca-4dd4-8993-2615c2fe004f", "ip_protocol": "ICMP", "last_updated": "2024-06-18T10:52:44.698368+02:00", "name": "ICMP", "natural_slug": "icmp__icmp_c52f", ... ... ...
I manage to get to the “secondary level” but not “lower” than for example destination_services in the example above. Not sure this is the right way, could anyone suggest a better / working method, please?
The dot approach mentioned / tried below does not work. I guess this has something to do with a mix of lists, arrays and dictionaries?
`
-
name: API CALL (Nautobot GET rules)
ansible.builtin.uri:
url: https://{{ nautobot_ip }}/api/plugins/firewall/policy-rule/?depth=4
method: GET
validate_certs: false
headers:
Authorization: Token {{ nautobot_token }}
register: firewall_rules -
name: SET FACT (Firewall policy rules)
ansible.builtin.set_fact:
firewall_policy_rules: “{{ firewall_rules[‘json’][‘results’] | json_query(‘[].{ dst_services: destination_services, dst_services_names: destination_services.names } ‘) }}”
… … …
`
My goal here is to create complete mapping (dictionary) of all firewall rules that could be used in further tasks. I hope my question makes sense. I also have some objects that have even more children than destination_services mentioned above.
kuda is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.