# JSON Response - limit search top 20lines only- HTTP Monitor script

**URL:** <https://community.dynatrace.com/t/json-response-limit-search-top-20lines-only-http-monitor-script/30973>\
**Category:** Synthetic Monitoring\
**Tags:** http-monitor, synthetic-monitoring\
**Created:** [March 30, 2021, 10:20pm UTC](https://community.dynatrace.com/t/json-response-limit-search-top-20lines-only-http-monitor-script/30973 "2021-03-30T22:20:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![shahrukh\_niazi](https://avatars.discourse-cdn.com/v4/letter/s/ecd19e/32.png) [@shahrukh\_niazi](https://community.dynatrace.com/u/shahrukh_niazi)\
**Post date:** [March 30, 2021, 10:20pm UTC](https://community.dynatrace.com/t/json-response-limit-search-top-20lines-only-http-monitor-script/30973/1 "2021-03-30T22:20:35Z")

</div>

We have a swagger API which outputs a JSON response that has status detail about the execution of our batchjob.

In my post execution script of HTTPMonitor of Dynatrace synthetics, I have this logic

_**responseObject = JSON.parse(response.getResponseBody());**_

_**responseObject.runs.forEach(x =\> {**_

_&nbsp;&nbsp;&nbsp; **if (x.success != true) {**_

_&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; **api.fail(x.id + " failed");**_

_&nbsp;&nbsp;&nbsp; **}** _

_**});**_

Batch jobs runs once a day. Our swagger JSON response has status details of last 50executions in the JSON body. I’m only interested in the 0 response - which has the status info of basically today’s execution & ignore all the rest.&nbsp; The above logic works when last 50th execution has no “success&nbsp;:fail” in them

Anyone knows how to limit the search in post execution script of an HTTP Monitor to only look for 0 iteration,&nbsp; or ,&nbsp; search first 20lines only & ignore rest of the JSON payload, and if you find “success&nbsp;:true” that means batch job ran successfully. Because&nbsp;first 20 lines has the last execution detail in **it..**

---

<div class="post-metadata">

**Author:** ![shahrukh\_niazi](https://avatars.discourse-cdn.com/v4/letter/s/ecd19e/32.png) [@shahrukh\_niazi](https://community.dynatrace.com/u/shahrukh_niazi)\
**Post date:** [March 30, 2021, 10:27pm UTC](https://community.dynatrace.com/t/json-response-limit-search-top-20lines-only-http-monitor-script/30973/2 "2021-03-30T22:27:34Z")

</div>

![shahrukh_niazi_0-1617143137089.png](https://global.discourse-cdn.com/dynatrace/original/1X/aa852da86ffe7cf84d772036dadbb1a73b9e500a.png)

 ![shahrukh_niazi_1-1617143247394.png](https://global.discourse-cdn.com/dynatrace/original/3X/b/4/b4da986630accac53383e31e913258e1f24a943c.png)

---

<div class="post-metadata">

**Author:** ![MichalGebacki](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/michalgebacki/32/41585_2.png) [@MichalGebacki](https://community.dynatrace.com/u/MichalGebacki)\
**Post date:** [April 22, 2022, 9:14am UTC](https://community.dynatrace.com/t/json-response-limit-search-top-20lines-only-http-monitor-script/30973/3 "2022-04-22T09:14:50Z")

</div>

Hello everyone!

This thread is left unanswered so far, but maybe somebody would find anything that would help anyone who faces similar issue like mentioned above now or in future?

Thank you in advance for any feedback!

---

<div class="post-metadata">

**Author:** ![hannahmac](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/hannahmac/32/41823_2.png) [@hannahmac](https://community.dynatrace.com/u/hannahmac)\
**Post date:** [April 25, 2022, 12:54pm UTC](https://community.dynatrace.com/t/json-response-limit-search-top-20lines-only-http-monitor-script/30973/4 "2022-04-25T12:54:39Z")

</div>

You can parse the response body as json. I guess you’d want something like:

_**var responseBody = response.getResponseBody();**_  
_ **var** _&nbsp;_ **json** __**Data =** _&nbsp;_ **JSON**__ **.** __**parse**__ **(responseBody);**_  
_ **var ps=** __**json**__ **Data.runs[0].success;**_
