# Logstash converts singleton array to string

**URL:** <https://discuss.elastic.co/t/logstash-converts-singleton-array-to-string/280900>\
**Category:** Logstash\
**Created:** [August 10, 2021, 9:14am UTC](https://discuss.elastic.co/t/logstash-converts-singleton-array-to-string/280900 "2021-08-10T09:14:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![GitSpree23](https://avatars.discourse-cdn.com/v4/letter/g/65b543/32.png) [@GitSpree23](https://discuss.elastic.co/u/GitSpree23)\
**Post date:** [August 10, 2021, 9:14am UTC](https://discuss.elastic.co/t/logstash-converts-singleton-array-to-string/280900/1 "2021-08-10T09:14:02Z")

</div>

I'm using

```auto
mutate {
    add_field => { "new_field" => ["X"] }
  }

```

to create an array of integers which can be appended to downstream.

But logstash output reads as `"new_field" => "X"`.

---

<div class="post-metadata">

**Author:** ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)\
**Post date:** [August 10, 2021, 11:37am UTC](https://discuss.elastic.co/t/logstash-converts-singleton-array-to-string/280900/2 "2021-08-10T11:37:46Z")

</div>

This only works if you add more than 1 value. Then it will convert to an array.

```auto
mutate {
    add_field => { "new_field" => "x" }
  }

mutate {
    add_field => { "new_field" => "y" }
  }

```

That will create `new_field: [x, y]`

If you only want to create an array with 1 item then I use Ruby. All you are really doing is setting a new field with a value and wrapping in `[` `]`.

```auto
  ruby {
    code => "event.set('new_field', [event.get('old_field')])"
  }

or

  ruby {
    code => "event.set('new_field', ['X'])"
  }

```

---

<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:** [September 7, 2021, 11:38am UTC](https://discuss.elastic.co/t/logstash-converts-singleton-array-to-string/280900/3 "2021-09-07T11:38:35Z")

</div>

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