{"id":16925442,"url":"https://github.com/alejandrodevs/activemodel_json_validator","last_synced_at":"2025-03-21T01:28:34.648Z","repository":{"id":56842144,"uuid":"202768239","full_name":"alejandrodevs/activemodel_json_validator","owner":"alejandrodevs","description":"A simple json validator based on ActiveModel.","archived":false,"fork":false,"pushed_at":"2019-10-10T20:11:11.000Z","size":26,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-28T11:33:39.480Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/alejandrodevs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-16T17:05:11.000Z","updated_at":"2019-10-10T20:10:32.000Z","dependencies_parsed_at":"2022-08-29T05:10:15.166Z","dependency_job_id":null,"html_url":"https://github.com/alejandrodevs/activemodel_json_validator","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alejandrodevs%2Factivemodel_json_validator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alejandrodevs%2Factivemodel_json_validator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alejandrodevs%2Factivemodel_json_validator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alejandrodevs%2Factivemodel_json_validator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alejandrodevs","download_url":"https://codeload.github.com/alejandrodevs/activemodel_json_validator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244720465,"owners_count":20498800,"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":[],"created_at":"2024-10-13T20:10:39.202Z","updated_at":"2025-03-21T01:28:34.627Z","avatar_url":"https://github.com/alejandrodevs.png","language":"Ruby","readme":"# ActiveModelJsonValidator\n[![Build Status](https://travis-ci.com/alejandrodevs/activemodel_json_validator.svg?branch=master)](https://travis-ci.org/alejandrodevs/activemodel_json_validator) [![Coverage Status](https://coveralls.io/repos/github/alejandrodevs/activemodel_json_validator/badge.svg?branch=master)](https://coveralls.io/github/alejandrodevs/activemodel_json_validator?branch=master)\n\nThis gem aims to provide an easy way to validate json and jsonb attributes against a JSON schema. This gem is based on ActiveModel and [`json-schema`](https://github.com/ruby-json-schema/json-schema).\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'activemodel_json_validator'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install activemodel_json_validator\n\n## Usage\n\nAdd your json validation in the model:\n\n```ruby\nclass User \u003c ApplicationRecord\n  validates :preferences, json: true\nend\n```\n\nBy default this validation will find an schema in:\n`app/models/schemas/user/preferences.json`.\n\n```json\n{\n  \"type\": \"object\",\n  \"$schema\": \"http://json-schema.org/draft-04/schema\",\n  \"required\": [\n    \"locale\",\n    \"currency\"\n  ],\n  \"properties\": {\n    \"locale\": { \"type\": \"string\" },\n    \"currency\": { \"type\": \"string\" },\n    \"subscribed\": { \"type\": \"boolean\" }\n  }\n}\n```\n\n```ruby\nuser = User.new\nuser.preferences = { locale: 'en', currency: 'USD' }\nuser.valid? # =\u003e true\n\nuser.preferences = { currency: 100, subscribed: 'true' }\nuser.valid? # =\u003e false\nuser.errors[:preferences] # =\u003e Invalid json\n```\n\nCustom schema path could be passed to the validator:\n\n```ruby\nclass User \u003c ApplicationRecord\n  validates :preferences, json: {\n    schema: Rails.root.join('schemas', 'preferences.json').to_s\n  }\nend\n```\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 tags, 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/alejandrodevs/activemodel_json_validator. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the ActivemodelJsonValidator project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/alejandrodevs/activemodel_json_validator/blob/master/CODE_OF_CONDUCT.md).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falejandrodevs%2Factivemodel_json_validator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falejandrodevs%2Factivemodel_json_validator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falejandrodevs%2Factivemodel_json_validator/lists"}