# Ruby to combine Object Array

**URL:** <https://discuss.elastic.co/t/ruby-to-combine-object-array/132050>\
**Category:** Logstash\
**Created:** [May 16, 2018, 7:24am UTC](https://discuss.elastic.co/t/ruby-to-combine-object-array/132050 "2018-05-16T07:24:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dhivya\_Buvanesh](https://avatars.discourse-cdn.com/v4/letter/d/ad7895/32.png) [@Dhivya\_Buvanesh](https://discuss.elastic.co/u/Dhivya_Buvanesh)\
**Post date:** [May 16, 2018, 7:24am UTC](https://discuss.elastic.co/t/ruby-to-combine-object-array/132050/1 "2018-05-16T07:24:20Z")

</div>

Need Help with ruby code ( I have no knowledge with ruby) on how to combine nested array objects as one Dict ? , as I am facing issues with elastic getting"Object in arrays are not well supported Error" ,

Also I tried "nested" with "mapping" and mutate - convert but nothing seems to help

Input Data:  
_{_  
\_"timestamp" : "1315294917923", \_  
_"layers" : {_  
_"data": [_  
_{"type": "8","seq": "1"},_  
_{"fixed\_value": "","fixed\_timestamp": "0x000000000001"}_  
_]_  
_} }_

I want the final data uploaded to elastic to be as

_{_  
\_"timestamp" : "1315294917923", \_  
_"layers" : {_  
_"data": {"type": "8","seq": "1", "fixed\_value": "","fixed\_timestamp": "0x000000000001"_  
_}_  
_}_

the "data" from a list is combined and converted as one Dict. Any input would be of great help

---

<div class="post-metadata">

**Author:** ![paz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paz/32/28003_2.png) [@paz](https://discuss.elastic.co/u/paz)\
**Post date:** [May 16, 2018, 12:16pm UTC](https://discuss.elastic.co/t/ruby-to-combine-object-array/132050/2 "2018-05-16T12:16:08Z")

</div>

That should do it

```auto
filter {
  ruby {
    code => "
      event.set('[layers][data]', Hash[*event.get('[layers][data]').map(&:to_a).flatten])
    "
  }
}
```

---

<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:** [June 13, 2018, 12:16pm UTC](https://discuss.elastic.co/t/ruby-to-combine-object-array/132050/3 "2018-06-13T12:16:10Z")

</div>

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