# Remove json object from nested log

**URL:** https://discuss.elastic.co/t/remove-json-object-from-nested-log/325468
**Category:** Logstash
**Created:** [February 14, 2023, 12:03pm UTC](https://discuss.elastic.co/t/remove-json-object-from-nested-log/325468 "2023-02-14T12:03:08Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Sharoze\_Meraj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sharoze_meraj/32/116263_2.png) [@Sharoze\_Meraj](https://discuss.elastic.co/u/Sharoze_Meraj)
#### Post date: [February 14, 2023, 12:03pm UTC](https://discuss.elastic.co/t/remove-json-object-from-nested-log/325468/1 "2023-02-14T12:03:08Z")

</div>

How can I use ruby code or some other filter plugin to detect and remove json object fields from my nested json logs.

This is required because the fields can either be json objects or strings. If I remove the json objects after parsing all the fields then the next time the key becomes a string I won't face a mapper\_exception.

I have tried to write ruby code and got close with following:

```auto
ruby {
        code => '
            event.to_hash.each do |field, value|
                if value.is_a?(Hash) 
                    event.remove(field)
                end
            end
        '
  }

```

But this only removes the fields parsed from the objects instead of removing the objects themselves.

---

<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: [March 14, 2023, 12:03pm UTC](https://discuss.elastic.co/t/remove-json-object-from-nested-log/325468/2 "2023-03-14T12:03:53Z")

</div>

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