# Converting a hash of key and values to a array of objects

**URL:** <https://discuss.elastic.co/t/converting-a-hash-of-key-and-values-to-a-array-of-objects/76856>\
**Category:** Logstash\
**Created:** [February 28, 2017, 7:41pm UTC](https://discuss.elastic.co/t/converting-a-hash-of-key-and-values-to-a-array-of-objects/76856 "2017-02-28T19:41:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Saravanan\_Sathyamoor](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/saravanan_sathyamoor/32/15953_2.png) [@Saravanan\_Sathyamoor](https://discuss.elastic.co/u/Saravanan_Sathyamoor)\
**Post date:** [February 28, 2017, 7:41pm UTC](https://discuss.elastic.co/t/converting-a-hash-of-key-and-values-to-a-array-of-objects/76856/1 "2017-02-28T19:41:54Z")

</div>

I have a json like  
{  
"230":{"startDatetime":"2017-07-21T07:00:00","endDatetime":"2017-08-07T06:59:59"},  
"232":{"startDatetime":"2017-07-21T07:00:00","endDatetime":"2017-08-07T06:59:59"}  
}  
and i need to convert to  
[  
{"location":"230","startDatetime":"2017-07-21T07:00:00","endDatetime":"2017-08-07T06:59:59"},{"location":"232","startDatetime":"2017-07-21T07:00:00","endDatetime":"2017-08-07T06:59:59"}  
]

Can we do this in logstash?

---

<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:** [March 14, 2017, 8:29am UTC](https://discuss.elastic.co/t/converting-a-hash-of-key-and-values-to-a-array-of-objects/76856/2 "2017-03-14T08:29:12Z")

</div>

Yes, but as I suspect the 230 and 232 are dynamic and not something you can hardcode into your configuration you need to use a ruby 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:** [April 11, 2017, 8:29am UTC](https://discuss.elastic.co/t/converting-a-hash-of-key-and-values-to-a-array-of-objects/76856/3 "2017-04-11T08:29:12Z")

</div>

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