Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Documentation on rubydoc.info: https://www.rubydoc.info/github/jddf/jddf-ruby
This gem is a Ruby implementation of JSON Data Definition Format, a schema language for JSON. You can use this gem to:
You can install this gem by running:
gem install jddf
Or if you're using Bundler:
gem 'jddf'
The two most important classes offered by the JDDF
module are:
Schema
, which represents a JDDF schema,Validator
, which can validate a Schema
against any parsed
JSON data, andValidationError
, which represents a single validation
problem with the input. Validator#validate
returns an array of these.Here's a working example:
require 'jddf'
# In this example, we're passing in a Hash directly into Schema#from_json, but
# this type of Hash is exactly what JSON#parse returns.
schema = JDDF::Schema.from_json({
'properties' => {
'name' => { 'type' => 'string' },
'age' => { 'type' => 'uint32' },
'phones' => {
'elements' => { 'type' => 'string' }
}
}
})
# Like before, in order to keep things simple we're construct raw Ruby values
# here. But you can also get this sort of data by parsing JSON using the
# standard library's JSON#parse.
#
# This input data is perfect. It satisfies all the schema requirements.
input_ok = {
'name' => 'John Doe',
'age' => 43,
'phones' => [
'+44 1234567',
'+44 2345678'
]
}
# This input data has problems. "name" is missing, "age" has the wrong type,
# and "phones[1]" has the wrong type.
input_bad = {
'age' => '43',
'phones' => [
'+44 1234567',
442345678
]
}
# Validator can validate schemas against inputs. Validator#validate returns an
# array of ValidationError.
#
# These ValidationError instances are portable -- every implementation of JDDF,
# across every language, returns the same errors.
validator = JDDF::Validator.new
result_ok = validator.validate(schema, input_ok)
result_bad = validator.validate(schema, input_bad)
p result_ok.size # 0
p result_bad.size # 3
# This error indicates that "name" is missing.
#
# #<struct JDDF::ValidationError instance_path=[], schema_path=["properties", "name"]
p result_bad[0]
# This error indicates that "age" has the wrong type.
#
# #<struct JDDF::ValidationError instance_path=["age"], schema_path=["properties", "age", "type"]>
p result_bad[1]
# This error indicates that "phones[1]" has the wrong type.
#
# #<struct JDDF::ValidationError instance_path=["phones", "1"], schema_path=["properties", "phones", "elements", "type"]>
p result_bad[2]
FAQs
Unknown package
We found that jddf demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.