# How to replace ' to " with gsub

**URL:** https://discuss.elastic.co/t/how-to-replace-to-with-gsub/226612
**Category:** Logstash
**Created:** [April 6, 2020, 4:24am UTC](https://discuss.elastic.co/t/how-to-replace-to-with-gsub/226612 "2020-04-06T04:24:43Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![lusynda](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lusynda/32/53557_2.png) [@lusynda](https://discuss.elastic.co/u/lusynda)
#### Post date: [April 6, 2020, 4:24am UTC](https://discuss.elastic.co/t/how-to-replace-to-with-gsub/226612/1 "2020-04-06T04:24:43Z")

</div>

Hi all  
How can i use gsub to replace ' to become ", i need it to parse json data. So some how json can only parse data field with "" and not '' so i need to replace ' to ".

Can anyone help me

Thanks in advance

---

<div class="post-metadata">

### Author: ![Robo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/robo/32/38295_2.png) [@Robo](https://discuss.elastic.co/u/Robo)
#### Post date: [April 6, 2020, 6:24am UTC](https://discuss.elastic.co/t/how-to-replace-to-with-gsub/226612/2 "2020-04-06T06:24:46Z")

</div>

```auto
filter {
      mutate {
         gsub => [
           "message", "'", """
         ]
      }
      json {
        source => "message"
      }
 }

```

does this work?

---

<div class="post-metadata">

### Author: ![lusynda](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lusynda/32/53557_2.png) [@lusynda](https://discuss.elastic.co/u/lusynda)
#### Post date: [April 6, 2020, 8:15am UTC](https://discuss.elastic.co/t/how-to-replace-to-with-gsub/226612/3 "2020-04-06T08:15:46Z")

</div>

nope it does not work, log say that the """ expected one of [\\t\\r\\n], \"\#\", \"{\", \",\", \"]\"

---

<div class="post-metadata">

### Author: ![Robo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/robo/32/38295_2.png) [@Robo](https://discuss.elastic.co/u/Robo)
#### Post date: [April 6, 2020, 8:36am UTC](https://discuss.elastic.co/t/how-to-replace-to-with-gsub/226612/4 "2020-04-06T08:36:11Z")

</div>

```auto
filter {
      mutate {
         gsub => [
           "message", "\'", "\""
         ]
      }
      json {
        source => "message"
      }
 }

```

try to escape characters

---

<div class="post-metadata">

### Author: ![lusynda](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lusynda/32/53557_2.png) [@lusynda](https://discuss.elastic.co/u/lusynda)
#### Post date: [April 6, 2020, 9:11am UTC](https://discuss.elastic.co/t/how-to-replace-to-with-gsub/226612/5 "2020-04-06T09:11:28Z")

</div>

Well i have try to escape characters but it got worst, however luckily i manage to got it working now.  
All i have to do is to enclose ' with " " and enclose " with ' ' and it work.  
Still dont quite understand but it work.

---

<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: [May 4, 2020, 9:11am UTC](https://discuss.elastic.co/t/how-to-replace-to-with-gsub/226612/6 "2020-05-04T09:11:43Z")

</div>

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