# How can I flatten an array in my document

**URL:** <https://discuss.elastic.co/t/how-can-i-flatten-an-array-in-my-document/235807>\
**Category:** Logstash\
**Created:** [June 4, 2020, 4:10pm UTC](https://discuss.elastic.co/t/how-can-i-flatten-an-array-in-my-document/235807 "2020-06-04T16:10:05Z")\
**Posts on this page:** 1\
**Showing post:** 3

<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:** [June 4, 2020, 4:21pm UTC](https://discuss.elastic.co/t/how-can-i-flatten-an-array-in-my-document/235807/3 "2020-06-04T16:21:08Z")

</div>

Use a ruby filter. I have not tested it but something like this...

```
ruby {
    code => '
        props = event.get("stringProperties")
        if props
            props.each { |x|
                key = x["key"]
                event.set("stringProperties.#{key}", x["value"])
            }
            event.remove("stringProperties")
        end
    }
}
```

---

_[View the full topic](https://discuss.elastic.co/t/how-can-i-flatten-an-array-in-my-document/235807)._
