# Question on logstash removing field from json string and saving back to same field

**URL:** https://discuss.elastic.co/t/question-on-logstash-removing-field-from-json-string-and-saving-back-to-same-field/267677
**Category:** Logstash
**Created:** [March 18, 2021, 2:02pm UTC](https://discuss.elastic.co/t/question-on-logstash-removing-field-from-json-string-and-saving-back-to-same-field/267677 "2021-03-18T14:02:40Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![rgreen](https://avatars.discourse-cdn.com/v4/letter/r/f04885/32.png) [@rgreen](https://discuss.elastic.co/u/rgreen)
#### Post date: [March 18, 2021, 2:02pm UTC](https://discuss.elastic.co/t/question-on-logstash-removing-field-from-json-string-and-saving-back-to-same-field/267677/1 "2021-03-18T14:02:41Z")

</div>

Is it possible to read a json string, remove specified fields then have that json string saved back into a single field with-ought parsing the json data into separate fields. So i would be reading a field from a database table called message: {"client": "ABC", "routnumber": "123789550", "Source": "Customer", "lastname": "smith"} .. Remove the field lastname. and have that json string saved into logstash as  
message: {"client": "ABC", "routnumber": "123789550", "Source": "Customer"}

---

<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: [March 18, 2021, 6:09pm UTC](https://discuss.elastic.co/t/question-on-logstash-removing-field-from-json-string-and-saving-back-to-same-field/267677/2 "2021-03-18T18:09:41Z")

</div>

If you install the [logstash-filter-json\_encode](https://www.elastic.co/guide/en/logstash/current/plugins-filters-json_encode.html) filter then you can do it...

```
input { generator { count => 1 lines => [''] } }
filter {
    mutate { add_field => { "[foo]" => '{ "a": 1, "b" : 2}' } }
    json { source => "foo" target => "[@metadata][json]" }
    mutate { remove_field => ["[@metadata][json][b]" ] }
    json_encode { source => "[@metadata][json]" target => "foo" }
}
output { stdout { codec => rubydebug { metadata => false } } }

```

will produce

```
       "foo" => "{\"a\":1}",
```

---

<div class="post-metadata">

### Author: ![rgreen](https://avatars.discourse-cdn.com/v4/letter/r/f04885/32.png) [@rgreen](https://discuss.elastic.co/u/rgreen)
#### Post date: [March 18, 2021, 6:57pm UTC](https://discuss.elastic.co/t/question-on-logstash-removing-field-from-json-string-and-saving-back-to-same-field/267677/3 "2021-03-18T18:57:39Z")

</div>

THANK YOU .. that worked.

---

<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: [April 15, 2021, 6:57pm UTC](https://discuss.elastic.co/t/question-on-logstash-removing-field-from-json-string-and-saving-back-to-same-field/267677/4 "2021-04-15T18:57:47Z")

</div>

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