Fetching values of a single key repeating multiple times

Here’s an outline with best practices for making your inquiry.

My question: Is there a way to fetch the values of a single key which is having multiple instances throughout the json object response?

Would it be possible to fetch and print all the ‘flight_prices’ which is occurring multiple times throughout the response?

I have another question as to why can’t we use ‘*’ in the jsonpath in Postman if it part of the jsonpath library already. It even works for jsonpath online formatting tool.

Details (like screenshots):
Sample JSON Response:

{
    "itineraries": [
        {
            "number": 1,
            "origin_airport": "LAX",
            "destination_airport": "SFO",
            "more_details": [
                {
                    "number": 1,
                    "segments": [
                        {
                            "number": 1,
                            "flight_number": 123,
                            "legs": [
                                {
                                    "cabins": [
                                        {
                                            "cabin_class": "Economy",
                                            "seats_remaining": 5,
                                            "flight_prices":[
                                                20.2,
                                                25.3,
                                                30.1,
                                                50.24,
                                                120.12
                                            ] 
                                        }
                                    ]
                                }
                            ]
                        },
                        {
                            "number": 2,
                            "flight_number": 123,
                            "legs": [
                                {
                                    "cabins": [
                                        {
                                            "cabin_class": "Premium_Economy",
                                            "seats_remaining": 5,
                                            "flight_prices":[
                                                120.2,
                                                125.3,
                                                130.1,
                                                150.24,
                                                220.12
                                            ] 
                                        }
                                    ]
                                }
                            ]
                        },
                        {
                            "number": 3,
                            "flight_number": 123,
                            "legs": [
                                {
                                    "cabins": [
                                        {
                                            "cabin_class": "Business",
                                            "seats_remaining": 5,
                                            "flight_prices":[
                                                220.2,
                                                225.3,
                                                230.1,
                                                250.24,
                                                320.12
                                            ] 
                                        }
                                    ]
                                }
                            ]
                        }
                    ]
                }
            ]
        }
    ]
}

I’m not a DEV, but that JSON is exceptionally complex.

Objects within objects, and arrays within arrays.

I have a few helper functions from the following site, and none of them are able to pull out the flight_prices.

How to parse and search JSON in JavaScript | TechSlides

Postman doesn’t have a native JSONPath library. You parse the JSON into a JavaScript object, and search using JavaScript functions.

I agree mate, the json payload I work with is highly complex to be processed with limited library support in Postman. Thus, hoping the team comes up with some handy solution. And I did look at the link you shared, I think I might have a go at it and see how far I get, appreciate your assistance.

What I would probably do for this particular situation is to define a variable at the segments level.

That should be iterneraries[0].more_details[0]

Find out how many segments there are using length, and then do a for each loop to find the flight prices.

As flight prices is also an array, you will need an inner loop, where I would push all of the results to a new array.

Seems way over the top though.