Is there a possibility to validate JSON data using a proper JSON scheme? I put the data into Logstash, parsed it using JSON plugin but I want to make sure that the data match the given pattern. There are few fields where values must match items from an array (enum in JSON scheme) also value types in all fields must be the same as in pattern.
You'd have to write a custom filter plugin for this.
As you mentioned, I started writing my own filter plugin for Logstash. I have found that there is already a gem for JSON scheme validation. - https://rubygems.org/gems/json-schema/versions/2.6.2
Do I understand it correctly, that all I need in is to load scheme variable from a JSON-scheme file and use block code similiar to this?
if JSON::Validator.validate(schema, {@message)
event.set("validation", "invalid json data")
which would add a "validation" field and set it to "invalid json data"?
I have also problem with using this json-schema gem in my plugin. What I did was editing my Gemfile into this:
source 'https://rubygems.org'
gemspec
gem "logstash", :github => "elastic/logstash", :branch => "2.3"
gem 'json-schema', '~> 2.6', '>= 2.6.2'
Do I understand it correctly, that all I need in is to load scheme variable from a JSON-scheme file and use block code similiar to this?
if JSON::Validator.validate(schema, {@message)
event.set("validation", "invalid json data")
which would add a "validation" field and set it to "invalid json data"?
I don't now the APIs by heart, but it should at least be very similar to what you've written.
I have also problem with using this json-schema gem in my plugin. What I did was editing my Gemfile into this:
What you've done might work (I'm not fluent in Ruby gems) but the pattern for Logstash plugins is to add dependencies in the .gemspec file