# Mutate and empty values

**URL:** <https://discuss.elastic.co/t/mutate-and-empty-values/32498>\
**Category:** Logstash\
**Created:** [October 19, 2015, 2:59pm UTC](https://discuss.elastic.co/t/mutate-and-empty-values/32498 "2015-10-19T14:59:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![maisyweb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maisyweb/32/5063_2.png) [@maisyweb](https://discuss.elastic.co/u/maisyweb)\
**Post date:** [October 19, 2015, 2:59pm UTC](https://discuss.elastic.co/t/mutate-and-empty-values/32498/1 "2015-10-19T14:59:41Z")

</div>

Hi,

I'm using the mutate plugin to remove square brackets i'm getting while trying to transform an XML file into a json file

mutate { replace =\> ["checkInFrom", "%{[checkInFrom][0]}"] }

This is working well. The only issue I have is that if the checkInForm value is empty or does not exists i'm getting the following JSON output

"checkInFrom":"%{[checkInFrom][0]}"

I would like to be able to remove the checkInFrom key from the JSON result if it does not exists. Is this possible? This is what I have tried so far

if ["checkInFrom"] == "" {  
mutate { remove\_field =\> ["checkInFrom"] }  
}else{  
mutate { replace =\> ["checkInFrom", "%{[checkInFrom][0]}"] }  
}

Thanks

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [October 19, 2015, 3:04pm UTC](https://discuss.elastic.co/t/mutate-and-empty-values/32498/2 "2015-10-19T15:04:05Z")

</div>

How about this:

```
if [checkInFrom] {
  mutate {
    ...
  }
}
```

---

<div class="post-metadata">

**Author:** ![maisyweb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maisyweb/32/5063_2.png) [@maisyweb](https://discuss.elastic.co/u/maisyweb)\
**Post date:** [October 19, 2015, 3:18pm UTC](https://discuss.elastic.co/t/mutate-and-empty-values/32498/3 "2015-10-19T15:18:43Z")

</div>

I'm sure I tried that before but yes it does seem to work.

Thanks very much

---

<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:** [July 6, 2017, 5:26am UTC](https://discuss.elastic.co/t/mutate-and-empty-values/32498/4 "2017-07-06T05:26:11Z")

</div>

Closed on July 6, 2017, 5:26am UTC


