Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
J

json_schemer

> 编程语言
Open source

JSON Schema validator. Supports drafts 4, 6, 7, 2019-09, 2020-12, OpenAPI 3.0, and OpenAPI 3.1.

475 stars0 likes1 views
WebsiteGitHub

About

JSON Schema validator. Supports drafts 4, 6, 7, 2019-09, 2020-12, OpenAPI 3.0, and OpenAPI 3.1.

JSONSchemer

JSON Schema validator. Supports drafts 4, 6, 7, 2019-09, 2020-12, OpenAPI 3.0, and OpenAPI 3.1.

Installation

Add this line to your application's Gemfile:

ruby
gem 'json_schemer'

And then execute:

$ bundle

Or install it yourself as:

$ gem install json_schemer

Usage

…

Options

…

Global Configuration

Configuration options can be set globally by modifying JSONSchemer.configuration. Global options are applied to any new schemas at creation time (global configuration changes are not reflected in existing schemas). They can be overridden with the regular keyword arguments described above.

ruby
# configuration block
JSONSchemer.configure do |config|
  config.regexp_resolver = 'ecma'
end

# configuration accessors
JSONSchemer.configuration.insert_property_defaults = true

Custom Error Messages

Error messages can be customized using the x-error keyword and/or I18n translations. x-error takes precedence if both are defined.

x-error Keyword

…

I18n

When the I18n gem is loaded, custom error messages are looked up under the json_schemer key. It may be necessary to restart your application after adding the root key because the existence check is cached for performance reasons.

Translation keys are looked up in this order:

  1. $LOCALE.json_schemer.errors.$ABSOLUTE_KEYWORD_LOCATION
  2. $LOCALE.json_schemer.errors.$SCHEMA_ID.$KEYWORD_LOCATION
  3. $LOCALE.json_schemer.errors.$KEYWORD_LOCATION
  4. $LOCALE.json_schemer.errors.$SCHEMA_ID.$KEYWORD
  5. $LOCALE.json_schemer.errors.$SCHEMA_ID.*
  6. $LOCALE.json_schemer.errors.$META_SCHEMA_ID.$KEYWORD
  7. $LOCALE.json_schemer.errors.$META_SCHEMA_ID.*
  8. $LOCALE.json_schemer.errors.$KEYWORD
  9. $LOCALE.json_schemer.errors.*

Example translations file:

…

And output:

…

In the example above, custom error messsages are looked up using the following keys (in order until one is found):

  1. en.json_schemer.errors.'https://example.com/schema#/properties/abc/required'
  2. en.json_schemer.errors.'https://example.com/schema'.'#/properties/abc/required'
  3. en.json_schemer.errors.'#/properties/abc/required'
  4. en.json_schemer.errors.'https://example.com/schema'.required
  5. en.json_schemer.errors.'https://example.com/schema'.*
  6. en.json_schemer.errors.'http://json-schema.org/draft-07/schema#'.required
  7. en.json_schemer.errors.'http://json-schema.org/draft-07/schema#'.*
  8. en.json_schemer.errors.required
  9. en.json_schemer.errors.*

OpenAPI

…

CLI

The json_schemer executable takes a JSON schema file as the first argument followed by one or more JSON data files to validate. If there are any validation errors, it outputs them and returns an error code.

Validation errors are output as single-line JSON objects. The --errors option can be used to limit the number of errors returned or prevent output entirely (and fail fast).

The schema or data can also be read from stdin using -.

% json_schemer --help
Usage:
  json_schemer [options]  ...
  json_schemer [options]  -
  json_schemer [options] - ...
  json_schemer -h | --help
  json_schemer --version

Options:
  -e, --errors MAX                 Maximum number of errors to output
                                   Use "0" to validate with no output
  -h, --help                       Show help
  -v, --version                    Show version

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

Build Status

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/davishmcclurg/json_schemer.

License

The gem is available as open source under the terms of the MIT License.

Issues· 18 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rubyjson-schemajson-validationruby

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言