class LogStash::Codecs::JSON
The codec should be used to decode full json messages. If you are streaming JSON
messages delimited by 'n' then see the json_lines codec. Encoding will result in a single json string.
Public Instance Methods
decode(data) { |event(parse)| ... }
click to toggle source
# File lib/logstash/codecs/json.rb, line 27 def decode(data) begin yield LogStash::Event.new(JSON.parse(data)) rescue JSON::ParserError => e @logger.info("JSON parse failure. Falling back to plain-text", :error => e, :data => data) yield LogStash::Event.new("message" => data) end end
encode(data)
click to toggle source
# File lib/logstash/codecs/json.rb, line 37 def encode(data) @on_event.call(data.to_json) end