# Ruby filter - detect null values inside structure

**URL:** <https://discuss.elastic.co/t/ruby-filter-detect-null-values-inside-structure/205509>\
**Category:** Logstash\
**Created:** [October 28, 2019, 3:56pm UTC](https://discuss.elastic.co/t/ruby-filter-detect-null-values-inside-structure/205509 "2019-10-28T15:56:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MMH](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mmh/32/54449_2.png) [@MMH](https://discuss.elastic.co/u/MMH)\
**Post date:** [October 28, 2019, 3:56pm UTC](https://discuss.elastic.co/t/ruby-filter-detect-null-values-inside-structure/205509/1 "2019-10-28T15:56:11Z")

</div>

In my Logstash pipeline, I am loading JSON messages and later use a ruby filter to detect and apply special logic to fields with null values.

```auto
ruby {
    code => "
    event.to_hash.each { |key,value|
        if value == nil
            //some logic here
        end
    }"
}

```

It works great when the field has a null value, but I would like to expand it to the situation when field is a structure and some of these structure fields have a null value. Also, the whole situation can be more nested: structure -\> one of filed is nested structure -\> inner field has null value.  
What is the best approach to this challenge?

---

<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:** [October 28, 2019, 4:48pm UTC](https://discuss.elastic.co/t/ruby-filter-detect-null-values-inside-structure/205509/2 "2019-10-28T16:48:27Z")

</div>

Use a script and iterate over the objects. Something like [this](https://discuss.elastic.co/t/how-to-parse-json-array-to-get-object-count/170409/4) or [this](https://discuss.elastic.co/t/flatten-recursively-a-json-to-logstash-in-ruby/188076/2).

---

<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:** [November 25, 2019, 4:48pm UTC](https://discuss.elastic.co/t/ruby-filter-detect-null-values-inside-structure/205509/3 "2019-11-25T16:48:32Z")

</div>

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