[Python] jmespath filter nested objects based on exact match of the value of an attribute

Discussão em 'Python' iniciado por Stack, Julho 21, 2025.

  1. Stack

    Stack Membro Participativo

    Is it possible to get the Jmespath expression to return groups and group_elements based on the match on group_name?

    I haven't even been able to get group_elements so far so getting two objects returned is beyond me. ChatGPT is either no help or i am too dumb to get it to work.

    [*].changed_resource_value.group_elements[?group_name == 'contact_information_address']
    [0].changed_resource_value.group_elements[?group_name == 'contact_information_address']
    [*].changed_resource_value.group_elements.*[?group_name == 'contact_information_address'] # this returns false


    This is what i have tried so far:

    [
    {
    "changed_resource_value": {
    "groups": {
    "contact_information": {
    "group_name": "contact_information",
    "group_path": "group_elements.contact_information"
    },
    "contact_information_address": {
    "group_name": "contact_information_address",
    "group_path": "group_elements.contact_information_address"
    }
    },
    "group_elements": {
    "city": {
    "new_value": "some city",
    "old_value": "",
    "group_name": "contact_information_address",
    "group_path": "group_elements.contact_information_address",
    "element_name": "city"
    },
    "full_name": {
    "new_value": "some full name",
    "old_value": "",
    "group_name": "contact_information",
    "group_path": "group_elements.contact_information",
    "element_name": "full_name"
    }
    }
    },
    "id": "107a564f-9d0e-4a0d-b58b-6fd35ee78933"
    }
    ]

    Continue reading...

Compartilhe esta Página