# Using logstash+http\_poller to loop through JSON structure, run 2nd poller

**URL:** https://discuss.elastic.co/t/using-logstash-http-poller-to-loop-through-json-structure-run-2nd-poller/109121
**Category:** Logstash
**Created:** [November 26, 2017, 6:29am UTC](https://discuss.elastic.co/t/using-logstash-http-poller-to-loop-through-json-structure-run-2nd-poller/109121 "2017-11-26T06:29:38Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![dorj1234](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dorj1234/32/21339_2.png) [@dorj1234](https://discuss.elastic.co/u/dorj1234)
#### Post date: [November 26, 2017, 6:29am UTC](https://discuss.elastic.co/t/using-logstash-http-poller-to-loop-through-json-structure-run-2nd-poller/109121/1 "2017-11-26T06:29:38Z")

</div>

Hello,  
I have an http\_poller working and getting me an array of JSON structures.  
Is it possible in logstash to loop through one of the fields and for each one run a second http\_poller?

For example, let's say my structure has a "City" field. I would like to run a second REST API for each city. Can it be done without hitting ruby coding? or if I must use ruby - can you point me in the right direction on how ruby does JSON parsing?  
Or for ruby, how do I extract the "City" value from this json structure and then call a second http\_poller with that value as part of my URL?

{  
"City" : "Frankfurt",  
"Population" : "12345",  
"Some stat" : "10"  
},  
{  
"City" : "New York",  
"Population" : "123456",  
"Some stat" : "100"  
}

HTTP poller will run for each city in the "loop":  
...  
URL =\> { "https://...../%[current\_city\_field]" }  
...

Thanks in advance !  
JD

---

<div class="post-metadata">

### Author: ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)
#### Post date: [November 27, 2017, 6:30am UTC](https://discuss.elastic.co/t/using-logstash-http-poller-to-loop-through-json-structure-run-2nd-poller/109121/2 "2017-11-27T06:30:05Z")

</div>

> Is it possible in logstash to loop through one of the fields and for each one run a second http\_poller?

Not with an http\_poller _input_, but if there were a _filter_ with the same features as http\_poller perhaps it would be possible. Right now you'll have to write some Ruby code, either in a ruby filter or in a plugin. If you deserialize the JSON in the HTTP response by using a json codec in the http\_poller input you won't have to worry about JSON deserialization in the ruby filter.

A possible option, if you're able to periodically dump all the city mappings into a flat file, is to use a translate filter.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [December 25, 2017, 6:30am UTC](https://discuss.elastic.co/t/using-logstash-http-poller-to-loop-through-json-structure-run-2nd-poller/109121/3 "2017-12-25T06:30:34Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
