# Convert values in kv-pairs (using ruby filter)

**URL:** <https://discuss.elastic.co/t/convert-values-in-kv-pairs-using-ruby-filter/135035>\
**Category:** Logstash\
**Created:** [June 7, 2018, 5:29pm UTC](https://discuss.elastic.co/t/convert-values-in-kv-pairs-using-ruby-filter/135035 "2018-06-07T17:29:24Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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:** [June 7, 2018, 5:58pm UTC](https://discuss.elastic.co/t/convert-values-in-kv-pairs-using-ruby-filter/135035/2 "2018-06-07T17:58:46Z")

</div>

You have to use event.get/set now. And in case you ever have non-numerics in the set...

```auto
            kv = event.get('kvpairs')
            kv.to_hash.keys.each { |k|
                if kv[k].to_i.to_s == kv[k]
                    kv[k] = kv[k].to_i
                end
                if kv[k].to_f.to_s == kv[k]
                    kv[k] = kv[k].to_f
                end
            }
            event.set('kvpairs', kv)
        "

```

---

_[View the full topic](https://discuss.elastic.co/t/convert-values-in-kv-pairs-using-ruby-filter/135035)._
