# Logstash mutate gsub replace json key

**URL:** <https://discuss.elastic.co/t/logstash-mutate-gsub-replace-json-key/189681>\
**Category:** Logstash\
**Created:** [July 10, 2019, 7:35am UTC](https://discuss.elastic.co/t/logstash-mutate-gsub-replace-json-key/189681 "2019-07-10T07:35:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Suhee\_Kim](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/suhee_kim/32/45707_2.png) [@Suhee\_Kim](https://discuss.elastic.co/u/Suhee_Kim)\
**Post date:** [July 10, 2019, 7:35am UTC](https://discuss.elastic.co/t/logstash-mutate-gsub-replace-json-key/189681/1 "2019-07-10T07:35:25Z")

</div>

Hi,

I have been trying to replace '-' to '\_'  
like this,  
{ "hello-world" : "something" } -\> { "hello\_world" : "something" }

this is my setting for logstash

input {  
stdin {  
codec =\> json  
}  
}

filter {  
json { source =\> "message" }  
mutate { gsub =\> ["message", "-", "\_"] }  
}

output {  
stdout {  
codec =\> rubydebug {}  
}  
}

how can i change it?  
Please help me..

Thank you

---

<div class="post-metadata">

**Author:** ![sjabiulla](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sjabiulla/32/48429_2.png) [@sjabiulla](https://discuss.elastic.co/u/sjabiulla)\
**Post date:** [July 10, 2019, 12:23pm UTC](https://discuss.elastic.co/t/logstash-mutate-gsub-replace-json-key/189681/2 "2019-07-10T12:23:46Z")

</div>

Hi @Suhee_Kim  
Since you have used **codec =\> json** in **stdin** , by the time you reach filter your message is already converted to json fields. Hence message field is not available.

Below conf should replace '-' to '\_' .

```
input {
    stdin {
    }
}

filter {
    mutate { gsub => ["message", "-", "_"] }
    json { 
        source => "message"
        remove_field => ["message"]
    }
}

output {
    stdout {
    codec => rubydebug {}
    }
}
```

---

<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:** [August 7, 2019, 12:23pm UTC](https://discuss.elastic.co/t/logstash-mutate-gsub-replace-json-key/189681/3 "2019-08-07T12:23:55Z")

</div>

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