# Replace the value of a field

**URL:** <https://discuss.elastic.co/t/replace-the-value-of-a-field/210171>\
**Category:** Logstash\
**Created:** [December 2, 2019, 11:22am UTC](https://discuss.elastic.co/t/replace-the-value-of-a-field/210171 "2019-12-02T11:22:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![wedkarz014](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wedkarz014/32/48935_2.png) [@wedkarz014](https://discuss.elastic.co/u/wedkarz014)\
**Post date:** [December 2, 2019, 11:22am UTC](https://discuss.elastic.co/t/replace-the-value-of-a-field/210171/1 "2019-12-02T11:22:43Z")

</div>

Hi,  
I'm trying to add a few characters at the beginning and the end of a field but i have an error.  
This is what i'd like to add " { "info": " and "}"  
I tried:

```
   mutate {
        replace => { "message" => "{\"info\":%{message}}" }
      }

```

# 

```
   mutate {
        replace => { "message" => "\{\"info\":%{message}\}" }
      }

```

# 

```
   mutate { add_field => {"beginning "=>"{\"info\":" } }
   mutate { replace => { "message" =>" "%{beginning} %{message}"} }

```

Can you help me?

---

<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:** [December 2, 2019, 3:23pm UTC](https://discuss.elastic.co/t/replace-the-value-of-a-field/210171/2 "2019-12-02T15:23:20Z")

</div>

I would use mutate+gsub

```
 mutate { gsub => ["message", "^", '{ "info": ', "message", "$", "}"] }
```

---

<div class="post-metadata">

**Author:** ![wedkarz014](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wedkarz014/32/48935_2.png) [@wedkarz014](https://discuss.elastic.co/u/wedkarz014)\
**Post date:** [December 3, 2019, 7:36am UTC](https://discuss.elastic.co/t/replace-the-value-of-a-field/210171/3 "2019-12-03T07:36:21Z")

</div>

This is a multiline message so your proposition is incorrect - we have new text in each line.  
But it works:

```
   mutate {
        replace => { "message" => '{"info":%{message}}' }
      }
```

---

<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:** [December 31, 2019, 7:36am UTC](https://discuss.elastic.co/t/replace-the-value-of-a-field/210171/4 "2019-12-31T07:36:29Z")

</div>

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