# Repeated values with mutate filter in nested json output

**URL:** https://discuss.elastic.co/t/repeated-values-with-mutate-filter-in-nested-json-output/40298
**Category:** Logstash
**Created:** [January 27, 2016, 10:46pm UTC](https://discuss.elastic.co/t/repeated-values-with-mutate-filter-in-nested-json-output/40298 "2016-01-27T22:46:16Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![fraescaya10](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fraescaya10/32/7421_2.png) [@fraescaya10](https://discuss.elastic.co/u/fraescaya10)
#### Post date: [January 27, 2016, 10:46pm UTC](https://discuss.elastic.co/t/repeated-values-with-mutate-filter-in-nested-json-output/40298/1 "2016-01-27T22:46:16Z")

</div>

I have the following input log:  
`.... proto=6 source=10.13.30.47 ....`

I need the following output in json:

```
"data": {
    "key1": {
        "src": "10.13.30.47",
        "proto": 6
     },
    "key2": {
        "src": "10.13.30.47"
        "proto": 6
    }
}

```

I used the mutate filter to do this

```
mutate {
    rename => { "proto" => "[data][key1][proto]" }
    rename => { "proto" => "[data][key2][proto]" }
    rename => { "source" => "[data][key1][src]" }
    rename => { "source" => "[data][key2][src]" }
}

```

but when i use logstash with this configuration, the console output is :

```
{
    "\"":
    {
        "data":
        {
            "key1":
            {
                "proto":
                {
                    "\", \"":
                    {
                        "data":
                        {
                            "key2":
                            {
                                "proto":
                                {
                                    "\"": "6"
                                }
                            }
                        }
                    }
                },
                "src":
                {
                    "\", \"":
                    {
                        "data":
                        {
                            "key2":
                            {
                                "src":
                                {
                                    "\"": "10.13.30.47"
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```

---

<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: [January 28, 2016, 7:07am UTC](https://discuss.elastic.co/t/repeated-values-with-mutate-filter-in-nested-json-output/40298/2 "2016-01-28T07:07:51Z")

</div>

I can't explain this behavior, but trying to rename the same field multiple times doesn't seem like a good idea to me. I'd try this:

```auto
mutate {
  add_field => {
    "[data][key1][proto]" => "%{proto}"
    "[data][key1][src]" => "%{src}"
  }
}
mutate {
  rename => {
    "proto" => "[data][key2][proto]"
    "src" => "[data][key2][src]"
  }
}

```

---

<div class="post-metadata">

### Author: ![fraescaya10](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fraescaya10/32/7421_2.png) [@fraescaya10](https://discuss.elastic.co/u/fraescaya10)
#### Post date: [January 28, 2016, 3:38pm UTC](https://discuss.elastic.co/t/repeated-values-with-mutate-filter-in-nested-json-output/40298/3 "2016-01-28T15:38:29Z")

</div>

Thank you, that solves the problem for me, thank you very much.

---

<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:13am UTC](https://discuss.elastic.co/t/repeated-values-with-mutate-filter-in-nested-json-output/40298/4 "2017-07-06T05:13:56Z")

</div>


