# Logstash mutate filter always stringifies hash and array

**URL:** https://discuss.elastic.co/t/logstash-mutate-filter-always-stringifies-hash-and-array/25917
**Category:** Logstash
**Created:** [July 20, 2015, 1:48pm UTC](https://discuss.elastic.co/t/logstash-mutate-filter-always-stringifies-hash-and-array/25917 "2015-07-20T13:48:30Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![tamizhgeek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tamizhgeek/32/3790_2.png) [@tamizhgeek](https://discuss.elastic.co/u/tamizhgeek)
#### Post date: [July 20, 2015, 1:48pm UTC](https://discuss.elastic.co/t/logstash-mutate-filter-always-stringifies-hash-and-array/25917/1 "2015-07-20T13:48:30Z")

</div>

I have a json log file, which I am taking as a input with this config

```
input {
   file { filename }
   codec { json_lines }
}

```

Each line is a deeply nested JSON.

In the filters,

When I say

```
mutate { add_field => { "new_field_name" => "%{old_field_name}"}

```

- if the old\_field is a nested hash/array it is converted to a string and then added. Is there anyway I can preserve the type instead of stringifying it ?

---

<div class="post-metadata">

### Author: ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)
#### Post date: [July 20, 2015, 4:31pm UTC](https://discuss.elastic.co/t/logstash-mutate-filter-always-stringifies-hash-and-array/25917/2 "2015-07-20T16:31:16Z")

</div>

I suspect it isn't possible with the mutate filter, but you could definitely use a ruby filter:

```
ruby {
  code => "event['new_field_name'] = event['old_field_name']"
}

```

(I suspect this makes both fields refer to the same hash so if you modify the hash in another filter you might see both fields getting updated. In that case you have to to make a copy of the hash.)

---

<div class="post-metadata">

### Author: ![tamizhgeek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tamizhgeek/32/3790_2.png) [@tamizhgeek](https://discuss.elastic.co/u/tamizhgeek)
#### Post date: [July 20, 2015, 7:17pm UTC](https://discuss.elastic.co/t/logstash-mutate-filter-always-stringifies-hash-and-array/25917/3 "2015-07-20T19:17:43Z")

</div>

Thanks @magnusbaeck. Will try and update here 😄

---

<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 6, 2017, 5:34am UTC](https://discuss.elastic.co/t/logstash-mutate-filter-always-stringifies-hash-and-array/25917/4 "2017-07-06T05:34:11Z")

</div>


