# Remove multiple similar prefix events from a json variable

**URL:** <https://discuss.elastic.co/t/remove-multiple-similar-prefix-events-from-a-json-variable/268402>\
**Category:** Logstash\
**Created:** [March 25, 2021, 6:35pm UTC](https://discuss.elastic.co/t/remove-multiple-similar-prefix-events-from-a-json-variable/268402 "2021-03-25T18:35:44Z")\
**Posts on this page:** 3\
**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 25, 2021, 6:35pm UTC](https://discuss.elastic.co/t/remove-multiple-similar-prefix-events-from-a-json-variable/268402/1 "2021-03-25T18:35:44Z")

</div>

How can I remove multiple events from a json variable with a prefix such as "customer\_" ?  
I have used the json plugin to pull the data into a variable

`json { source => "message" target => "[@metadata][json]" }`

Now i am attempting to remove all of the events that start with "customer\_"

I was attempting to use the ruby plugin

````auto
ruby
{
	code =>
	"event.get('[@metadata][json]').to_hash.keys.each { |k| if k.start_with?('customer_') then event.remove('[@metadata][json][k]') end }"
}```
````

---

<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 25, 2021, 6:46pm UTC](https://discuss.elastic.co/t/remove-multiple-similar-prefix-events-from-a-json-variable/268402/2 "2021-03-25T18:46:01Z")

</div>

Use string interpolation

```
ruby { code => 'event.get("[@metadata][json]").to_hash.keys.each { |k| if k.start_with?("customer_") then event.remove("[@metadata][json][#{k}]") end }' }
```

---

<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 22, 2021, 6:46pm UTC](https://discuss.elastic.co/t/remove-multiple-similar-prefix-events-from-a-json-variable/268402/3 "2021-04-22T18:46:20Z")

</div>

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