# XML Filter :How to create array of objects using xml filter (xpath)

**URL:** <https://discuss.elastic.co/t/xml-filter-how-to-create-array-of-objects-using-xml-filter-xpath/144143>\
**Category:** Logstash\
**Created:** [August 13, 2018, 9:54am UTC](https://discuss.elastic.co/t/xml-filter-how-to-create-array-of-objects-using-xml-filter-xpath/144143 "2018-08-13T09:54:05Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [August 13, 2018, 6:20pm UTC](https://discuss.elastic.co/t/xml-filter-how-to-create-array-of-objects-using-xml-filter-xpath/144143/4 "2018-08-13T18:20:39Z")

</div>

Something like this:

```
    ruby { code => "
        c = event.get('code')
        i = event.get('id')
        n = event.get('name')
        a = []
        c.each_index { |k|
            h = { 'code' => c[k], 'id' => i[k], 'name' => n[k] }
            a << h
        }
        event.set('arrayOfHashes', a)
    "

```

Error handling is left as an exercise for the reader.

---

_[View the full topic](https://discuss.elastic.co/t/xml-filter-how-to-create-array-of-objects-using-xml-filter-xpath/144143)._
