# If condition for null in json field

**URL:** <https://discuss.elastic.co/t/if-condition-for-null-in-json-field/340475>\
**Category:** Logstash\
**Created:** [August 9, 2023, 4:09pm UTC](https://discuss.elastic.co/t/if-condition-for-null-in-json-field/340475 "2023-08-09T16:09:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wwalker](https://avatars.discourse-cdn.com/v4/letter/w/43a26b/32.png) [@wwalker](https://discuss.elastic.co/u/wwalker)\
**Post date:** [August 9, 2023, 4:09pm UTC](https://discuss.elastic.co/t/if-condition-for-null-in-json-field/340475/1 "2023-08-09T16:09:51Z")

</div>

I'm using the JDBC filter to pull info from a SQL database. If the field is blank, it generates the below:

```auto
"example": [
      {
        "contoso": ""
      }
    ]

```

I've tried the below to remove the empty field, but it doesn't seem to work. What am I doing wrong here?

```auto
if [example][0][contoso] == "" {
    mutate {
      remove_field => ["example"]
    }
  }

```

---

<div class="post-metadata">

**Author:** ![Rios](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rios/32/95745_2.png) [@Rios](https://discuss.elastic.co/u/Rios)\
**Post date:** [August 11, 2023, 12:59pm UTC](https://discuss.elastic.co/t/if-condition-for-null-in-json-field/340475/2 "2023-08-11T12:59:42Z")

</div>

Have you solved this?  
Your logic for the empty value field is OK. What is possible that you get null instead "". In that case:

```auto
if [example][0][contoso] {
    mutate {remove_field => ["example"] }
}

```

---

<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:** [September 8, 2023, 1:00pm UTC](https://discuss.elastic.co/t/if-condition-for-null-in-json-field/340475/3 "2023-09-08T13:00:24Z")

</div>

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