Class: LogStash::Codecs::JSON
- Inherits:
-
Base
- Object
- Base
- LogStash::Codecs::JSON
- Extended by:
- PluginMixins::ValidatorSupport::FieldReferenceValidationAdapter
- Includes:
- PluginMixins::ECSCompatibilitySupport::TargetCheck, PluginMixins::EventSupport::EventFactoryAdapter, PluginMixins::EventSupport::FromJsonHelper
- 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
- #decode(data, &block) ⇒ Object
- #encode(event) ⇒ Object
-
#initialize(*params) ⇒ JSON
constructor
A new instance of JSON.
- #register ⇒ Object
Constructor Details
#initialize(*params) ⇒ JSON
Returns a new instance of JSON.
51 52 53 54 55 56 57 58 |
# File 'lib/logstash/codecs/json.rb', line 51 def initialize(*params) super @original_field = ecs_select[disabled: nil, v1: '[event][original]'] @converter = LogStash::Util::Charset.new(@charset) @converter.logger = @logger end |
Instance Method Details
#decode(data, &block) ⇒ Object
64 65 66 |
# File 'lib/logstash/codecs/json.rb', line 64 def decode(data, &block) parse_json(@converter.convert(data), &block) end |
#encode(event) ⇒ Object
68 69 70 |
# File 'lib/logstash/codecs/json.rb', line 68 def encode(event) @on_event.call(event, event.to_json) end |
#register ⇒ Object
60 61 62 |
# File 'lib/logstash/codecs/json.rb', line 60 def register # no-op end |