{"id":15013071,"url":"https://github.com/skryukov/json_skooma","last_synced_at":"2025-04-07T14:13:55.118Z","repository":{"id":196684502,"uuid":"641598062","full_name":"skryukov/json_skooma","owner":"skryukov","description":"JSONSkooma is a Ruby library for validating JSONs against JSON Schemas.","archived":false,"fork":false,"pushed_at":"2024-12-25T10:08:19.000Z","size":89,"stargazers_count":22,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-31T12:09:15.955Z","etag":null,"topics":["hacktoberfest","json-schema","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/skryukov.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-16T20:09:12.000Z","updated_at":"2024-12-25T10:07:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"723a5de7-9312-484b-8459-a4310f7150f0","html_url":"https://github.com/skryukov/json_skooma","commit_stats":{"total_commits":36,"total_committers":3,"mean_commits":12.0,"dds":0.2777777777777778,"last_synced_commit":"f7326d145e7c6fac7e50b9e150df22a94c7ac1fb"},"previous_names":["skryukov/json_skooma"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skryukov%2Fjson_skooma","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skryukov%2Fjson_skooma/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skryukov%2Fjson_skooma/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skryukov%2Fjson_skooma/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/skryukov","download_url":"https://codeload.github.com/skryukov/json_skooma/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247666015,"owners_count":20975788,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacktoberfest","json-schema","ruby"],"created_at":"2024-09-24T19:43:42.105Z","updated_at":"2025-04-07T14:13:55.081Z","avatar_url":"https://github.com/skryukov.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# JSONSkooma – Sugar for your JSONs\n\n[![Gem Version](https://badge.fury.io/rb/json_skooma.svg)](https://rubygems.org/gems/json_skooma)\n[![Ruby](https://github.com/skryukov/json_skooma/actions/workflows/main.yml/badge.svg)](https://github.com/skryukov/json_skooma/actions/workflows/main.yml)\n\n\u003cimg align=\"right\" height=\"150\" width=\"150\" title=\"JSONSkooma logo\" src=\"./assets/logo.svg\"\u003e\n\nJSONSkooma is a Ruby library for validating JSONs against JSON Schemas.\n\n### Features\n\n- Supports JSON Schema 2019-09 and 2020-12\n- Supports custom dialects, vocabularies, keywords, format validators, output formatters \n- Supports custom schema resolvers\n\n\u003ca href=\"https://evilmartians.com/?utm_source=json_skooma\u0026utm_campaign=project_page\"\u003e\n\u003cimg src=\"https://evilmartians.com/badges/sponsored-by-evil-martians.svg\" alt=\"Built by Evil Martians\" width=\"236\" height=\"54\"\u003e\n\u003c/a\u003e\n\n## Installation\n\nInstall the gem and add to the application's Gemfile by executing:\n\n    $ bundle add json_skooma\n\nIf bundler is not being used to manage dependencies, install the gem by executing:\n\n    $ gem install json_skooma\n\n## Usage\n\n```ruby\nrequire \"json_skooma\"\n\n# Create a registry to store schemas, vocabularies, dialects, etc.\nJSONSkooma.create_registry(\"2020-12\", assert_formats: true)\n\n# Load a schema\nschema_hash = {\n  \"$schema\" =\u003e \"https://json-schema.org/draft/2020-12/schema\",\n  \"type\" =\u003e \"object\",\n  \"properties\" =\u003e {\n    \"name\" =\u003e {\"type\" =\u003e \"string\"},\n    \"race\" =\u003e {\"enum\" =\u003e %w[Nord Khajiit Argonian Breton Redguard Dunmer Altmer Bosmer Orc Imperial]},\n    \"class\" =\u003e {\"type\" =\u003e \"string\"},\n    \"level\" =\u003e {\"type\" =\u003e \"integer\", \"minimum\" =\u003e 1},\n    \"equipment\" =\u003e {\n      \"type\" =\u003e \"array\",\n      \"items\" =\u003e {\"type\" =\u003e \"string\"}\n    }\n  },\n  \"required\" =\u003e %w[name race class level]\n}\n\nschema = JSONSkooma::JSONSchema.new(schema_hash)\n\ndata_hash = {\n  name: \"Matz\",\n  race: \"Human\",\n  class: \"Dragonborn\",\n  level: 50,\n  equipment: %w[Ruby],\n}\n\nresult = schema.evaluate(data_hash)\n\nresult.valid? # =\u003e false\n\nresult.output(:basic)\n# {\"valid\"=\u003efalse,\n#  \"errors\"=\u003e\n#    [{\"instanceLocation\"=\u003e\"\",\n#      \"keywordLocation\"=\u003e\"/properties\",\n#      \"absoluteKeywordLocation\"=\u003e\"urn:uuid:f477b6ca-7308-4be6-b88c-e848b9002793#/properties\",\n#      \"error\"=\u003e\"Properties [\\\"race\\\"] are invalid\"},\n#     {\"instanceLocation\"=\u003e\"/race\",\n#      \"keywordLocation\"=\u003e\"/properties/race/enum\",\n#      \"absoluteKeywordLocation\"=\u003e\"urn:uuid:f477b6ca-7308-4be6-b88c-e848b9002793#/properties/race/enum\",\n#      \"error\"=\u003e\n#        \"The instance value \\\"Human\\\" must be equal to one of the elements in the defined enumeration: [\\\"Nord\\\", \\\"Khajiit\\\", \\\"Argonian\\\", \\\"Breton\\\", \\\"Redguard\\\", \\\"Dunmer\\\", \\\"Altmer\\\", \\\"Bosmer\\\", \\\"Orc\\\", \\\"Imperial\\\"]\"}]}\n```\n\n### Evaluating against a reference\n\n```ruby\nrequire \"json_skooma\"\n\n# Create a registry to store schemas, vocabularies, dialects, etc.\nJSONSkooma.create_registry(\"2020-12\", assert_formats: true)\n\n# Load a schema\nschema_hash = {\n  \"$schema\" =\u003e \"https://json-schema.org/draft/2020-12/schema\",\n  \"$defs\" =\u003e {\n    \"Foo\": {\n      \"type\" =\u003e \"object\",\n      \"properties\" =\u003e { \n        \"foo\" =\u003e {\"enum\" =\u003e [\"baz\"]}\n      },\n    }\n  }\n}\n\nschema = JSONSkooma::JSONSchema.new(schema_hash)\n\nresult = schema.evaluate({foo: \"bar\"}, ref: \"#/$defs/Foo\")\n\nresult.valid? # =\u003e false\n\nresult.output(:basic)\n# {\"valid\"=\u003efalse,\n#  \"errors\"=\u003e\n#   [{\"instanceLocation\"=\u003e\"\", \"keywordLocation\"=\u003e\"/properties\", \"absoluteKeywordLocation\"=\u003e\"urn:uuid:cb8fb0a0-ce16-416f-b5ba-2a6531992be9#/$defs/Foo/properties\", \"error\"=\u003e\"Properties [\\\"foo\\\"] are invalid\"},\n#    {\"instanceLocation\"=\u003e\"/foo\",\n#     \"keywordLocation\"=\u003e\"/properties/foo/enum\",\n#     \"absoluteKeywordLocation\"=\u003e\"urn:uuid:cb8fb0a0-ce16-416f-b5ba-2a6531992be9#/$defs/Foo/properties/foo/enum\",\n#     \"error\"=\u003e\"The instance value \\\"bar\\\" must be equal to one of the elements in the defined enumeration: [\\\"baz\\\"]\"}]}\n```\n\n### Handling External `$ref`s in JSON Schemas\n\nIn `JSONSkooma`, you can map `$ref` identifiers in your JSON schemas to local or remote sources.\n\nThis configuration allows `JSONSkooma` to automatically link `$ref` URIs to their corresponding schemas from specified sources:\n\n```yaml\n# schema.yml\n$schema: https://json-schema.org/draft/2020-12/schema\ntype: object\nproperties:\n  user:\n    $ref: http://local.example/user_definition.yaml\n  product:\n    $ref: http://remote.example/product_definition.yaml\n```\n\n```ruby\n# Initialize the JSONSkooma registry\nschema_registry = JSONSkooma.create_registry(\"2020-12\")\n\n# Add a local source for user definitions\nlocal_schemas_path = File.join(__dir__, \"schemas\", \"local\")\nschema_registry.add_source(\n  \"http://local.example/\",\n  JSONSkooma::Sources::Local.new(local_schemas_path)\n)\n\n# Add a remote source for product definitions\nschema_registry.add_source(\n  \"http://remote.example/\",\n  JSONSkooma::Sources::Remote.new(\"http://example.com/schemas/\")\n)\n\n# JSONSkooma now automatically resolves `$refs` to the appropriate schemas:\n# - http://local.example/user_definition.yaml -\u003e ./schemas/local/user_definition.yaml\n# - http://remote.example/product_definition.yaml -\u003e http://example.com/schemas/product_definition.yaml\n```\n\n## Alternatives\n\n- [json_schemer](https://github.com/davishmcclurg/json_schemer) – Draft 4, 6, 7, 2019-09 and 2020-12 compliant\n- [json-schema](https://github.com/voxpupuli/json-schema) – Draft 1, 2, 3, 4 and 6 compliant\n\n## Feature plans\n\n- Custom error messages\n- EcmaScript regexp\n- Short circuit errors\n- IRI as schema identifiers\n- Relative JSONPointer\n- More unit tests\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/skryukov/json_skooma.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskryukov%2Fjson_skooma","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fskryukov%2Fjson_skooma","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskryukov%2Fjson_skooma/lists"}