{"id":15554154,"url":"https://github.com/rmorlok/activejsonmodel","last_synced_at":"2025-07-07T12:10:50.285Z","repository":{"id":39204788,"uuid":"463718135","full_name":"rmorlok/activejsonmodel","owner":"rmorlok","description":"Active model objects that can be serialized to JSON","archived":false,"fork":false,"pushed_at":"2024-05-01T13:45:39.000Z","size":121,"stargazers_count":1,"open_issues_count":9,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-22T02:22:18.382Z","etag":null,"topics":["activemodel","json","rails","ruby","serialization"],"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/rmorlok.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-02-26T00:57:21.000Z","updated_at":"2022-08-21T19:39:45.000Z","dependencies_parsed_at":"2024-05-01T14:36:57.744Z","dependency_job_id":"d9bb46cc-8858-4385-8704-da6321a786b1","html_url":"https://github.com/rmorlok/activejsonmodel","commit_stats":{"total_commits":46,"total_committers":2,"mean_commits":23.0,"dds":"0.19565217391304346","last_synced_commit":"48b26f1667c75c96be6772a275080012d4fa2352"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":"mattbrictson/gem","purl":"pkg:github/rmorlok/activejsonmodel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rmorlok%2Factivejsonmodel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rmorlok%2Factivejsonmodel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rmorlok%2Factivejsonmodel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rmorlok%2Factivejsonmodel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rmorlok","download_url":"https://codeload.github.com/rmorlok/activejsonmodel/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rmorlok%2Factivejsonmodel/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264016542,"owners_count":23544608,"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":["activemodel","json","rails","ruby","serialization"],"created_at":"2024-10-02T14:50:19.802Z","updated_at":"2025-07-07T12:10:45.279Z","avatar_url":"https://github.com/rmorlok.png","language":"Ruby","readme":"# Active JSON Model\n\n[![Gem Version](https://badge.fury.io/rb/activejsonmodel.svg)](https://rubygems.org/gems/activejsonmodel)\n![Github Actions CI](https://github.com/rmorlok/activejsonmodel/actions/workflows/ci.yaml/badge.svg)\n\nA library for creating Active Models that can serialize/deserialize to JSON. This includes full support for validation\nand change detection through nested models.\n\nActive JSON Model can optionally be combined with Active Record to create nested child models via JSON/JSONB columns. \n\n---\n\n- [Quick start](#quick-start)\n- [Gem on RubyGems](https://rubygems.org/gems/activejsonmodel)\n- [Support](#support)\n- [License](#license)\n- [Code of conduct](#code-of-conduct)\n- [Contribution guide](#contribution-guide)\n\n## Quick start\n\nInstall the gem:\n\n```\n$ gem install activejsonmodel\n```\n\nIf not using in an auto-loading context (i.e. Rails), import it:\n\n```ruby\nrequire \"active_json_model\"\n```\n\ndefine a model:\n\n```ruby\nclass Point\n  include ActiveJsonModel::Model\n  \n  json_attribute :x, Integer\n  json_attribute :y, Integer\nend\n```\n\ncreate an instance of a model:\n\n```ruby\norigin = Point.new(x: 0, y:0)\n# =\u003e #\u003cPoint:0x00007f9f0d0e6538 @mutations_before_last_save=nil, @mutations_from_database=nil, @x=0, @x_is_default=false, @y=0, @y_is_default=false\u003e\n```\n\nexport it to a JSON-like hash:\n\n```ruby\ndata = origin.dump_to_json\n# =\u003e {:x=\u003e0, :y=\u003e0}\n```\n\nencode it as JSON:\n\n```ruby\nJSON.dump(origin.dump_to_json)\n# =\u003e \"{\\\"x\\\":0,\\\"y\\\":0}\"\n```\n\nload data from a hash object:\n\n```ruby\npoint2 = Point.load({x: 17, y:42})\n# =\u003e #\u003cPoint:0x00007f9f0d10d5c0 @_active_json_model_loaded=true, @mutations_before_last_save=nil, @mutations_from_database=nil, @x=17, @x_is_default=false, @y=42, @y_is_default=false\u003e\n```\n\nload from a raw JSON string:\n\n```ruby\npoint3 = Point.load(\"{\\\"x\\\":12,\\\"y\\\":19}\")\n# =\u003e #\u003cPoint:0x00007fe9c0113c88 @_active_json_model_loaded=true, @mutations_before_last_save=nil, @mutations_from_database=nil, @x=12, @x_is_default=false, @y=19, @y_is_default=false\u003e\n```\n\nnest models:\n\n```ruby\nclass Rectangle\n  include ActiveJsonModel::Model\n\n  json_attribute :top_left, Point\n  json_attribute :bottom_right, Point\n  \n  def contains(point)\n    point.x \u003e= top_left.x \u0026\u0026 \n      point.x \u003c= bottom_right.x \u0026\u0026\n      point.y \u003c= top_left.y \u0026\u0026\n      point.y \u003e= bottom_right.y\n  end\nend\n```\n\nIf you are using Active Record, use the model as an attribute:\n\n```ruby\n# db/migrate/20220101000001_create_image_annotations.rb\nclass CreateImageAnnotations \u003c ActiveRecord::Migration[7.0]\n  def change\n    create_table :image_annotations do |t|\n      t.jsonb      :region_of_interest, null: false, default: {}\n      t.string     :note, null: false, default: ''\n    end\n  end\nend\n\n# app/models/image_annotation.rb\nclass ImageAnnotation \u003c ActiveRecord::Base \n  attribute :region_of_interest, Rectangle.attribute_type\nend\n\n# use...\nrect = Rectangle.new(\n  top_left: Point.new(x: 10, y: 100),\n  bottom_right: Point.new(x: 110, y: 0)\n)\nia = ImageAnnotation.new(region_of_interest: rect, note: \"Check out this mistake\")\nia.save\n```\n\n## Support\n\nIf you want to report a bug, or have ideas, feedback or questions about the gem, [let me know via GitHub issues](https://github.com/rmorlok/activejsonmodel/issues/new) and I will do my best to provide a helpful answer. Happy hacking!\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](LICENSE.txt).\n\n## Code of conduct\n\nEveryone interacting in this project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](CODE_OF_CONDUCT.md).\n\n## Contribution guide\n\nPull requests are welcome!\n\n### Development Setup\n\n```bash\nbrew install rbenv\n```\n\nAdd the following to `~/.zshrc`:\n\n```bash\nRBENV=`which rbenv`\nif [ $RBENV ] ; then\n  export PATH=$HOME/.rbenv/bin:$PATH\n  eval \"$(rbenv init -)\"\nfi\n```\n\nReload the `~/.zshrc`.\n\nInstall development ruby version:\n\n```bash\ncat .ruby-version | xargs rbenv install\n```\n\nExit and re-enter the directory to make sure the current version of ruby is used. Install dependencies:\n\n```bash\nbundle install\n```\n\n### Running Tests\n\nActive JSON Model uses [minitest](https://github.com/minitest/minitest). To run tests, use rake:\n\n```bash\nrake test\n```\n\n### Building Gem Locally\n\nBuild the gem to `pkg/activejsonmodel-x.x.x.gem`:\n\n```bash\nrake build\n```\n\nInstall the gem locally and import it:\n\n```bash\n$ gem install ./pkg/activejsonmodel-x.x.x.gem\nSuccessfully installed activejsonmodel-x.x.x\nParsing documentation for activejsonmodel-x.x.x\nInstalling ri documentation for activejsonmodel-x.x.x\nDone installing documentation for activejsonmodel after 0 seconds\n1 gem installed\n\n$ irb\nirb(main):001:0\u003e require 'active_json_model'\n=\u003e true \n```\n\n### Releasing a new version\n\n1. Update `lib/activejsonmodel/version.rb`\n\n```ruby\nmodule ActiveJsonModel\n  VERSION = \"x.x.x\".freeze\nend\n```\n\n2. Commit all changes\n3. Release the changes using rake:\n\n```bash\n$ rake release\nactive_json_model x.x.x built to pkg/active_json_model-x.x.x.gem.\nTagged vx.x.x.\nPushed git commits and release tag.\nPushing gem to https://rubygems.org...\nSuccessfully registered gem: active_json_model (x.x.x)\nPushed active_json_model x.x.x to rubygems.org\nDon't forget to publish the release on GitHub!\n```\n\nNote that this pushes changes to github and creates a draft release on github. ","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frmorlok%2Factivejsonmodel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frmorlok%2Factivejsonmodel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frmorlok%2Factivejsonmodel/lists"}