# Creating Array in Logstash

**URL:** <https://discuss.elastic.co/t/creating-array-in-logstash/93801>\
**Category:** Logstash\
**Created:** [July 19, 2017, 3:29pm UTC](https://discuss.elastic.co/t/creating-array-in-logstash/93801 "2017-07-19T15:29:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jacoblemperle](https://avatars.discourse-cdn.com/v4/letter/j/96bed5/32.png) [@jacoblemperle](https://discuss.elastic.co/u/jacoblemperle)\
**Post date:** [July 19, 2017, 3:29pm UTC](https://discuss.elastic.co/t/creating-array-in-logstash/93801/1 "2017-07-19T15:29:33Z")

</div>

I am looking to create an array in Logstash right now with an object inside of it.

Something that looks like this is what I am trying right now I am getting the error Ruby exception occurred: can't convert Array into String

event.set(["id\_holder"], "[{ "uid": event.get([uid]), "id": event.get([id]) }]")

I am looking to make it similar to this  
[{ "uid": 12423423423, "id": 6456456456 }]

Is there a way to do this in logstash?

---

<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:** [July 19, 2017, 3:43pm UTC](https://discuss.elastic.co/t/creating-array-in-logstash/93801/2 "2017-07-19T15:43:03Z")

</div>

What you posted as an expected result is not really an array, more like a hash.  
What you might be after is nested fields, which can easily be added with the mutate filter.

---

<div class="post-metadata">

**Author:** ![jacoblemperle](https://avatars.discourse-cdn.com/v4/letter/j/96bed5/32.png) [@jacoblemperle](https://discuss.elastic.co/u/jacoblemperle)\
**Post date:** [July 19, 2017, 4:04pm UTC](https://discuss.elastic.co/t/creating-array-in-logstash/93801/3 "2017-07-19T16:04:36Z")

</div>

I need to have it wrapped in the array though, how would i get the hash to be wrapped in the array? Sorry I don't have much experience using the mutate filter and I am pretty confused with it.

---

<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:** [July 20, 2017, 10:28am UTC](https://discuss.elastic.co/t/creating-array-in-logstash/93801/4 "2017-07-20T10:28:49Z")

</div>

Try this one, should produce what you are after.

```auto
    ruby {
        code => "
            event.set('id_holder', [Hash['uid',event.get('uid'),'id',event.get('id')]])
        "
    }
```

Example rubydebug output snippet

```auto
"id_holder" => [
    [0] {
        "uid" => "uid_value",
        "id" => "id_value"
    }
]
```

---

<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:** [August 17, 2017, 10:28am UTC](https://discuss.elastic.co/t/creating-array-in-logstash/93801/5 "2017-08-17T10:28:57Z")

</div>

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