# Fetching values of a single key repeating multiple times

**URL:** <https://community.postman.com/t/fetching-values-of-a-single-key-repeating-multiple-times/42765>\
**Category:** Help Hub\
**Tags:** json, javascript\
**Created:** [January 10, 2023, 9:15pm UTC](https://community.postman.com/t/fetching-values-of-a-single-key-repeating-multiple-times/42765 "2023-01-10T21:15:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gonsag](https://avatars.discourse-cdn.com/v4/letter/g/47e85d/32.png) [@gonsag](https://community.postman.com/u/gonsag)\
**Post date:** [January 10, 2023, 9:15pm UTC](https://community.postman.com/t/fetching-values-of-a-single-key-repeating-multiple-times/42765/1 "2023-01-10T21:15:50Z")

</div>

> 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:

```auto
{
    "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
                                            ] 
                                        }
                                    ]
                                }
                            ]
                        }
                    ]
                }
            ]
        }
    ]
}

```

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [January 11, 2023, 11:20am UTC](https://community.postman.com/t/fetching-values-of-a-single-key-repeating-multiple-times/42765/2 "2023-01-11T11:20:13Z")

</div>

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](http://techslides.com/how-to-parse-and-search-json-in-javascript)

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

---

<div class="post-metadata">

**Author:** ![gonsag](https://avatars.discourse-cdn.com/v4/letter/g/47e85d/32.png) [@gonsag](https://community.postman.com/u/gonsag)\
**Post date:** [January 11, 2023, 9:06pm UTC](https://community.postman.com/t/fetching-values-of-a-single-key-repeating-multiple-times/42765/3 "2023-01-11T21:06:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [January 12, 2023, 9:24am UTC](https://community.postman.com/t/fetching-values-of-a-single-key-repeating-multiple-times/42765/4 "2023-01-12T09:24:57Z")

</div>

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.
