# Convert field to an array

**URL:** <https://discuss.elastic.co/t/convert-field-to-an-array/303884>\
**Category:** Logstash\
**Created:** [May 3, 2022, 11:00pm UTC](https://discuss.elastic.co/t/convert-field-to-an-array/303884 "2022-05-03T23:00:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JeremyP](https://avatars.discourse-cdn.com/v4/letter/j/43a26b/32.png) [@JeremyP](https://discuss.elastic.co/u/JeremyP)\
**Post date:** [May 3, 2022, 11:00pm UTC](https://discuss.elastic.co/t/convert-field-to-an-array/303884/1 "2022-05-03T23:00:16Z")

</div>

Hello,

I'm looking to convert the following field to a hash of values....

Source Field:

```auto
"ip_addresses": "{192.168.1.1, 192.168.1.2, 192.168.1.3}"

```

Desired Result:

```auto
"ip_addresses": [
        "192.168.1.1",
        "192.168.1.2",
        "192.168.1.3"
      ],

```

Any help would be appreciated.... Thank you!

---

<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:** [May 4, 2022, 3:16am UTC](https://discuss.elastic.co/t/convert-field-to-an-array/303884/2 "2022-05-04T03:16:27Z")

</div>

> [@JeremyP](#):
>
> `"ip_addresses": "{192.168.1.1, 192.168.1.2, 192.168.1.3}"`

I have not tested it, but you could try

```
mutate {
    gsub => ["ip_addresses", "[{}]", "" ]
    split => { "ip_addresses" => "," }
}
mutate { strip => ["ip_addresses"] }

```

Strip has to be in a separate mutate filter to get operations done in the right order.

---

<div class="post-metadata">

**Author:** ![JeremyP](https://avatars.discourse-cdn.com/v4/letter/j/43a26b/32.png) [@JeremyP](https://discuss.elastic.co/u/JeremyP)\
**Post date:** [May 4, 2022, 4:47pm UTC](https://discuss.elastic.co/t/convert-field-to-an-array/303884/3 "2022-05-04T16:47:32Z")

</div>

Thank you Badger for your help.

---

<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:** [June 1, 2022, 4:47pm UTC](https://discuss.elastic.co/t/convert-field-to-an-array/303884/4 "2022-06-01T16:47:43Z")

</div>

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