Class: LogStash::Codecs::JSON
- Inherits:
-
Base
- Object
- Base
- LogStash::Codecs::JSON
- Defined in:
- lib/logstash/codecs/json.rb
Overview
This codec may be used to decode (via inputs) and encode (via outputs) full JSON messages. If the data being sent is a JSON array at its root multiple events will be created (one per element).
If you are streaming JSON messages delimited by ‘n’ then see the ‘json_lines` codec.
Encoding will result in a compact JSON representation (no line terminators or indentation)
If this codec recieves a payload from an input that is not valid JSON, then it will fall back to plain text and add a tag ‘_jsonparsefailure`. Upon a JSON failure, the payload will be stored in the `message` field.
Instance Method Summary collapse
Instance Method Details
#decode(data, &block) ⇒ Object
37 38 39 |
# File 'lib/logstash/codecs/json.rb', line 37 def decode(data, &block) parse(@converter.convert(data), &block) end |
#encode(event) ⇒ Object
41 42 43 |
# File 'lib/logstash/codecs/json.rb', line 41 def encode(event) @on_event.call(event, event.to_json) end |
#register ⇒ Object
32 33 34 35 |
# File 'lib/logstash/codecs/json.rb', line 32 def register @converter = LogStash::Util::Charset.new(@charset) @converter.logger = @logger end |