logstash-plugins/logstash-filter-json

ensure source field is a string before attempting deserialization

colinsurprenant opened this issue · 2 comments

per elastic/logstash#3032 when attempting to parse a field that is not a string, very strange exception is thrown. we should first check that the source field is a string content and error for this first then attempt deserialization.

👍

I was hoping that the source field can be both a valid JSON or a string. For the former, the use case is that the json filter is part of a chain of filters.

For instance, I have the following input:
{"results": [{"id" : "a1", "msg" : "hello"}, {"id" : "a2", "msg": "world"}]}

The objective is to split the array and have each element be its own event. I'm using the split filter to split an a JSON array in a JSON input. The output from split filter is:
{"results": {"id": "a1", "msg" : "hello"}}
{"results": {"id": "a2", "msg" : "world"}}

Now, this gets passed down the chain to the json filter to have the inner object extracted to its own event, but it fails with the
Trouble parsing json :exception=>java.lang.ClassCastException: org.jruby.java.proxies.MapJavaProxy cannot be cast to org.jruby.RubyIO, :level=>:warn

The reason is simply that the inner object is not a string.