# Rename json nested fields using mutate

**URL:** https://discuss.elastic.co/t/rename-json-nested-fields-using-mutate/340063
**Category:** Logstash
**Created:** [August 3, 2023, 3:17pm UTC](https://discuss.elastic.co/t/rename-json-nested-fields-using-mutate/340063 "2023-08-03T15:17:10Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![mario\_kazela](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mario_kazela/32/124314_2.png) [@mario\_kazela](https://discuss.elastic.co/u/mario_kazela)
#### Post date: [August 3, 2023, 3:17pm UTC](https://discuss.elastic.co/t/rename-json-nested-fields-using-mutate/340063/1 "2023-08-03T15:17:10Z")

</div>

Hi,

I have an issue with mutating a nested JSON fields using Logstash.  
Example of my nested JSON:

```auto
"test_results_result_legacy_entities_hashtags": [
    {
      "indices": [
        34,
        43
      ],
      "text": "out"
    },
    {
      "indices": [
        44,
        50
      ],
      "text": "getout"
    }
]

```

I try mutate using the syntax `rename => {"[test_results_result_legacy_entities_hashtags][text]" => "Hashtags"}`, but seem it is not works. Any solution that you can suggest me?

Thanks

---

<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: [August 3, 2023, 4:59pm UTC](https://discuss.elastic.co/t/rename-json-nested-fields-using-mutate/340063/2 "2023-08-03T16:59:50Z")

</div>

[test\_results\_result\_legacy\_entities\_hashtags] is an array, if you want to rename fields within member of the array you would use

```
rename => {
    [test_results_result_legacy_entities_hashtags][0][text] => "newName"
    [test_results_result_legacy_entities_hashtags][1][text] => "otherNewName"
}

```

If you want to create a [Hashtags] array then I think you can do that using mutate+rename, but if the number of array entries varies then you will need to use a ruby filter.

---

<div class="post-metadata">

### Author: ![mario\_kazela](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mario_kazela/32/124314_2.png) [@mario\_kazela](https://discuss.elastic.co/u/mario_kazela)
#### Post date: [August 4, 2023, 1:07am UTC](https://discuss.elastic.co/t/rename-json-nested-fields-using-mutate/340063/3 "2023-08-04T01:07:36Z")

</div>

Yeah Thanks bro. It works.

But, if there any method that can I rename that two fields within member of the array in one name?

Thanks.

---

<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: [August 4, 2023, 1:19am UTC](https://discuss.elastic.co/t/rename-json-nested-fields-using-mutate/340063/4 "2023-08-04T01:19:46Z")

</div>

```
        rename => {
            "[test_results_result_legacy_entities_hashtags][0][text]" => "[Hashtags][0]"
            "[test_results_result_legacy_entities_hashtags][1][text]" => "[Hashtags][1]"
        }

```

will work.

---

<div class="post-metadata">

### Author: ![mario\_kazela](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mario_kazela/32/124314_2.png) [@mario\_kazela](https://discuss.elastic.co/u/mario_kazela)
#### Post date: [August 4, 2023, 3:32am UTC](https://discuss.elastic.co/t/rename-json-nested-fields-using-mutate/340063/6 "2023-08-04T03:32:03Z")

</div>

Thanks!!! It works.

---

<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 1, 2023, 3:32am UTC](https://discuss.elastic.co/t/rename-json-nested-fields-using-mutate/340063/7 "2023-09-01T03:32:17Z")

</div>

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