# Picking the 8 first occurrence in a JSON response

**URL:** <https://community.gatling.io/t/picking-the-8-first-occurrence-in-a-json-response/2161>\
**Category:** Gatling (Open-Source)\
**Created:** [March 30, 2015, 7:54pm UTC](https://community.gatling.io/t/picking-the-8-first-occurrence-in-a-json-response/2161 "2015-03-30T19:54:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![fugmag](https://avatars.discourse-cdn.com/v4/letter/f/d78d45/32.png) [@fugmag](https://community.gatling.io/u/fugmag)\
**Post date:** [March 30, 2015, 7:54pm UTC](https://community.gatling.io/t/picking-the-8-first-occurrence-in-a-json-response/2161/1 "2015-03-30T19:54:35Z")

</div>

given my working simulation, this gives me all the occurrences of instances in a json response:

`

.check(_jsonPath_(**"$.membershipCoupons[?(@.membershipId==’${MemberId}’)].coupons[?(@.activationDate==null)].offerId"**).findAll.optional.saveAs( **“itemList”** ))

`

and this gives me the fist one in the same response:

`

.check(_jsonPath_(**"$.membershipCoupons[?(@.membershipId==’${MemberId}’)].coupons[0].offerId"**).findAll.optional.saveAs( **“itemList”** ))

`

but how can I get just the 8 first occurrences?

This does not work:

`  
.check(_jsonPath_(**"$.membershipCoupons[?(@.membershipId==’${MemberId}’)].coupons[0-7].offerId"**).findAll.optional.saveAs( **“itemList”** ))

`

Thanks

---

<div class="post-metadata">

**Author:** ![fugmag](https://avatars.discourse-cdn.com/v4/letter/f/d78d45/32.png) [@fugmag](https://community.gatling.io/u/fugmag)\
**Post date:** [March 30, 2015, 8:17pm UTC](https://community.gatling.io/t/picking-the-8-first-occurrence-in-a-json-response/2161/2 "2015-03-30T20:17:32Z")

</div>

.check(_jsonPath_(**"$.membershipCoupons[?(@.membershipId==’${MemberId}’)].coupons[0,1,2,3,5,5,6,7].offerId"**).findAll.optional.saveAs( **“itemList”** ))

---

<div class="post-metadata">

**Author:** ![empty\_account](https://avatars.discourse-cdn.com/v4/letter/e/74df32/32.png) [@empty\_account](https://community.gatling.io/u/empty_account)\
**Post date:** [March 30, 2015, 8:31pm UTC](https://community.gatling.io/t/picking-the-8-first-occurrence-in-a-json-response/2161/3 "2015-03-30T20:31:48Z")

</div>

Can you not do a ‘take’ or a ‘dropWhile’ on the full collection or something?

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [March 30, 2015, 9:39pm UTC](https://community.gatling.io/t/picking-the-8-first-occurrence-in-a-json-response/2161/4 "2015-03-30T21:39:53Z")

</div>

From JsonPath’s spec: [http://goessner.net/articles/JsonPath/](http://goessner.net/articles/JsonPath/)

---

<div class="post-metadata">

**Author:** ![fugmag](https://avatars.discourse-cdn.com/v4/letter/f/d78d45/32.png) [@fugmag](https://community.gatling.io/u/fugmag)\
**Post date:** [March 31, 2015, 7:05am UTC](https://community.gatling.io/t/picking-the-8-first-occurrence-in-a-json-response/2161/5 "2015-03-31T07:05:11Z")

</div>

Thanks guys,

.check(_jsonPath_(**"$.membershipCoupons[?(@.membershipId==’${MemberId}’)].coupons[0:8].offerId"**).findAll.optional.saveAs( **“itemList”** ))

---

<div class="post-metadata">

**Author:** ![fugmag](https://avatars.discourse-cdn.com/v4/letter/f/d78d45/32.png) [@fugmag](https://community.gatling.io/u/fugmag)\
**Post date:** [March 31, 2015, 7:11am UTC](https://community.gatling.io/t/picking-the-8-first-occurrence-in-a-json-response/2161/6 "2015-03-31T07:11:25Z")

</div>

Is it possible to combine **?(@.activationDate==null** with **[0:8]**

in one expression?

I have

`

.check(_jsonPath_(**"$.membershipCoupons[?(@.membershipId==’${MemberId}’)].coupons[?(@.activationDate==null)].offerId"**).findAll.optional.saveAs( **“itemList”** ))

`  
and

`

.check(_jsonPath_(**"$.membershipCoupons[?(@.membershipId==’${MemberId}’)].coupons[0:8].offerId"**).findAll.optional.saveAs( **“itemList”** ))

`

something like:

`.check(*jsonPath*(**"$.membershipCoupons[?(@.membershipId=='${MemberId}')].coupons[?(@.activationDate==null) &&** **[0:8]****].offerId"**).findAll.optional.saveAs(**"itemList"**))`

?
