# How to split string into array of objects using logstash?

**URL:** <https://discuss.elastic.co/t/how-to-split-string-into-array-of-objects-using-logstash/135370>\
**Category:** Logstash\
**Created:** [June 11, 2018, 1:30pm UTC](https://discuss.elastic.co/t/how-to-split-string-into-array-of-objects-using-logstash/135370 "2018-06-11T13:30:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![stevefai](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stevefai/32/31039_2.png) [@stevefai](https://discuss.elastic.co/u/stevefai)\
**Post date:** [June 11, 2018, 1:30pm UTC](https://discuss.elastic.co/t/how-to-split-string-into-array-of-objects-using-logstash/135370/1 "2018-06-11T13:30:34Z")

</div>

Hello,

I'm trying to save some Java stacktrace data into Elasticsearch using Logstash.

Each event contains a multiline string like:  
"exception1: Exception Message 1  
exception2: Exception Message 2  
exception3: Exception Message 3"

I want to save this into Elasticsearch as an array of objects like:  
stacktrace\_exceptions: [{name: "exception 1", message: "Exception Message 1", {name: "exception 2", message: "Exception Message 2", ...}

So far I've managed to save the stacktrace into two different arrays using mutate split, like:  
exception\_names: ["exception 1", "exception 2", ...]  
exception\_messages: ["Exception Message 1", "Exception Message 2", ...]

But I'd like to save it as a single array of objects.

Is this possible?

---

<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 11, 2018, 1:48pm UTC](https://discuss.elastic.co/t/how-to-split-string-into-array-of-objects-using-logstash/135370/2 "2018-06-11T13:48:18Z")

</div>

I can't think how to do that, but if a hash will do then.

```auto
    mutate { split => { "message" => "
" } }
    kv { value_split => ":" field_split => "&" source => "message" target => "exceptionsHash" }

```

will return

```
"exceptionsHash" => {
    "exception3" => "Exception Message 3",
    "exception2" => "Exception Message 2",
    "exception1" => "Exception Message 1"
},
```

---

<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:** [July 9, 2018, 1:48pm UTC](https://discuss.elastic.co/t/how-to-split-string-into-array-of-objects-using-logstash/135370/3 "2018-07-09T13:48:26Z")

</div>

Closed on July 9, 2018, 1:48pm UTC

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