# How to apply json filter to every field that ends with "json"?

**URL:** https://discuss.elastic.co/t/how-to-apply-json-filter-to-every-field-that-ends-with-json/221652
**Category:** Logstash
**Created:** [March 2, 2020, 9:22am UTC](https://discuss.elastic.co/t/how-to-apply-json-filter-to-every-field-that-ends-with-json/221652 "2020-03-02T09:22:05Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![sahar](https://avatars.discourse-cdn.com/v4/letter/s/ea5d25/32.png) [@sahar](https://discuss.elastic.co/u/sahar)
#### Post date: [March 2, 2020, 9:22am UTC](https://discuss.elastic.co/t/how-to-apply-json-filter-to-every-field-that-ends-with-json/221652/1 "2020-03-02T09:22:05Z")

</div>

Hello,  
I'm extracting fields from the message using KV filter, some of these fields might be holding a json value - I would like to iterate all fields and check if the field key ends with "json", to apply json filter on the value.

How can I achieve that?  
Thanks for the help.

---

<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 2, 2020, 2:44pm UTC](https://discuss.elastic.co/t/how-to-apply-json-filter-to-every-field-that-ends-with-json/221652/2 "2020-03-02T14:44:54Z")

</div>

I think you would have to write code to do that in a ruby filter.

---

<div class="post-metadata">

### Author: ![sahar](https://avatars.discourse-cdn.com/v4/letter/s/ea5d25/32.png) [@sahar](https://discuss.elastic.co/u/sahar)
#### Post date: [March 3, 2020, 8:16pm UTC](https://discuss.elastic.co/t/how-to-apply-json-filter-to-every-field-that-ends-with-json/221652/3 "2020-03-03T20:16:52Z")

</div>

Indeed achieved this using ruby filter:

```
ruby {
	code => '
		event.to_hash.each do |k,v|
			if k.end_with?("json")
				event.set(k, JSON.parse(v))
			end
		end
	'
}

```

Thanks for the help.

---

<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 31, 2020, 8:17pm UTC](https://discuss.elastic.co/t/how-to-apply-json-filter-to-every-field-that-ends-with-json/221652/4 "2020-03-31T20:17:08Z")

</div>

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