# Logstash json filter plugin values as string

**URL:** <https://discuss.elastic.co/t/logstash-json-filter-plugin-values-as-string/256912>\
**Category:** Logstash\
**Created:** [November 27, 2020, 8:02pm UTC](https://discuss.elastic.co/t/logstash-json-filter-plugin-values-as-string/256912 "2020-11-27T20:02:51Z")\
**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:** [November 27, 2020, 9:00pm UTC](https://discuss.elastic.co/t/logstash-json-filter-plugin-values-as-string/256912/2 "2020-11-27T21:00:52Z")

</div>

I cannot help feeling there should be a way to do this in the mapping. You might want to ask in the elasticsearch forum if something like this would work.

```
"dynamic_templates": [
    {
        "everythingstring": { 
            "match" : "jsondoc*",
            "mapping" : { "type" : "text", "norms" : false }
    }
]

```

But if you really want to do it in logstash it would require a ruby filter

```
    ruby {
        code => '
            def toString(object, name, event)
                #puts "toString called for #{name}"
                if object
                    if object.kind_of?(Hash) and object != {}
                        object.each { |k, v| toString(v, "#{name}[#{k}]", event) }
                    elsif object.kind_of?(Array) and object != []
                        object.each_index { |i|
                            toString(object[i], "#{name}[#{i}]", event)
                        }
                    else
                        event.set(name, object.to_s)
                    end
                end
            end
            event.to_hash.each { |k, v|
                unless k == "@timestamp"
                    toString(v, "[#{k}]", event)
                end
            }
        '
    }
```

---

_[View the full topic](https://discuss.elastic.co/t/logstash-json-filter-plugin-values-as-string/256912)._
