Response selector for nested json

Hi All,

I wonder if somebody had tried this before, I have this response body:

{
    "id": "GENE",
    "tree": {
        "children": [
            {
                "id": "GENE::8A20835E-5173-4007-A4AE-6AED501886CD",
                "name": "ACTIVATING 1",
                "children": [
                    {
                        "type": "MutaGroup",
                        "id": "GENE::6C4C71D9-C0B0-4DB6-A23F-40955566208B",
                        "name": "ACTIVATING 2",
                        "children": [
                            {
                                "type": "MutaGroup",
                                "id": "GENE::6E479405-7B48-4409-B9BD-839325CA1539",
                                "name": "ACTIVATING 3"
                            }
                        ]
                    },
                    {
                        "type": "MutaGroup",
                        "id": "GENE::0C615FDA-E7A5-4940-8B8D-2CE866A95810",
                        "name": "ACTIVATING 4",
                        "children": [
                            {
                                "type": "MutaGroup",
                                "id": "GENE::F5D41514-98FF-11E9-A51F-91FA4247F9E3",
                                "name": "ACTIVATING 5"
                            }
                        ]
                    }
                ]
            }
        ],
        "name": "GENE",
        "id": "GENE::GENE"
    },
    "geneName": "GENE",
    "version": 1
}

I was trying to use https://k6.io/docs/javascript-api/k6-http/response/response-json-selector to find for instance “name”: “ACTIVATING 5” and return its id “id”: "GENE::F5D41514-98FF-11E9-A51F-91FA4247F9E3"

I tried some of the suggested GJSON paths, for instance tree.children.#(name==“ACTIVATING 1”).id but it only works at the first level, is there a way to find values deeper in the Json body?

I know that I can create a GJSON path to find the id I need for this json example but I was looking for a solution that would work for responses with multiple nested objects

Hello!

This selector should work:

tree.children.#.children.#.children.#(name=="ACTIVATING 5").id

The GJSON playground came in handy for this.