{"id":18728638,"url":"https://github.com/rubyonworld/ruson","last_synced_at":"2026-05-06T03:31:20.072Z","repository":{"id":174008126,"uuid":"540254238","full_name":"RubyOnWorld/ruson","owner":"RubyOnWorld","description":"A Ruby serialization/deserialization library to convert Ruby Objects into JSON and back","archived":false,"fork":false,"pushed_at":"2022-09-23T02:49:00.000Z","size":86,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-19T20:32:26.628Z","etag":null,"topics":["convert","deserialization","json","library","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/RubyOnWorld.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-09-23T02:48:44.000Z","updated_at":"2022-09-27T20:56:19.000Z","dependencies_parsed_at":"2024-01-28T04:34:02.466Z","dependency_job_id":null,"html_url":"https://github.com/RubyOnWorld/ruson","commit_stats":null,"previous_names":["rubyonworld/ruson"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/RubyOnWorld/ruson","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RubyOnWorld%2Fruson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RubyOnWorld%2Fruson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RubyOnWorld%2Fruson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RubyOnWorld%2Fruson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RubyOnWorld","download_url":"https://codeload.github.com/RubyOnWorld/ruson/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RubyOnWorld%2Fruson/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32677862,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-06T02:33:58.958Z","status":"ssl_error","status_checked_at":"2026-05-06T02:33:39.611Z","response_time":117,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["convert","deserialization","json","library","ruby","serialization"],"created_at":"2024-11-07T14:22:31.399Z","updated_at":"2026-05-06T03:31:20.060Z","avatar_url":"https://github.com/RubyOnWorld.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ruson\n\nA Ruby serialization/deserialization library to convert Ruby Objects into JSON and back\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'ruson'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install ruson\n\n## Usage\n\n### Basic\n\npost.json\n```json\n{\n  \"title\": \"Ruson\",\n  \"content\": \"Welcome!\"\n}\n```\n\n```ruby\nrequire 'ruson'\n\nclass Post \u003c Ruson::Base  \n  field :title\n  field :content\nend\n\njson = File.read('post.json')\npost = Post.new(json)\npost.title #=\u003e 'Ruson'\npost.content #=\u003e 'Welcome!'\n```\n\n#### name\n\npost.json\n```json\n{\n  \"title\": \"Ruson\",\n  \"post_url\": \"http://sample.com\"\n}\n```\n\n```ruby\nrequire 'ruson'\n\nclass Post \u003c Ruson::Base\n  field :title\n  field :url, name: 'post_url'\nend\n\njson = File.read('post.json')\npost = Post.new(json)\npost.url #=\u003e 'http://sample.com'\n```\n\n#### nilable\n\npost.json\n```json\n{\n  \"title\": \"Ruson\",\n  \"post_url\": \"http://sample.com\"\n}\n```\n\n```ruby\nclass Post \u003c Ruson::Base\n  field :title, nilable: false\n  field :url, name: 'post_url'\nend\n\njson = File.read('post.json')\npost = Post.new(json) #=\u003e Ruson::NotNilException\n```\n\n#### nested class\n\n##### class\n\npost.json\n```json\n{\n  \"title\": \"Ruson\",\n  \"post_url\": \"http://sample.com\",\n  \"picture\": {\n    \"title\": \"nice picture\",\n    \"url\": \"http://sample.com/picture.png\"\n  }\n}\n```\n\n```ruby\nrequire 'ruson'\n\nclass Post \u003c Ruson::Base\n  field :title\n  field :picture, class: Picture\nend\n\nclass Picture \u003c Ruson::Base\n  field :title\n  field :url\nend\n\njson = File.read('post.json')\npost = Post.new(json)\npost.picture.url #=\u003e 'http://sample.com/picture.png'\n```\n\n###### Primary classes\n\n* Ruson::Array\n* Ruson::Boolean\n* Ruson::Float\n* Ruson::Integer\n* Ruson::Time\n\n\npost.json\n```json\n{\n  \"title\": \"Ruson\",\n  \"items\": [\"orange\", \"apple\"],\n  \"is_new\": \"true\",\n  \"rate\": \"3.8\",\n  \"view\": \"1234\",\n  \"expired_at\": 1575608299\n}\n```\n\n```ruby\nclass Post \u003c Ruson::Base\n  field :title\n  field :items, class: Ruson::Array\n  field :is_new, class: Ruson::Boolean\n  field :rate, class: Ruson::Float\n  field :view, class: Ruson::Integer\n  field :expired_at, class: Ruson::Time\nend\n\njson = File.read('post.json')\npost = Post.new(json)\npost.items #=\u003e [\"orange\", \"apple\"]\npost.is_new #=\u003e true\npost.rate #=\u003e 3.8\npost.view #=\u003e 1234\npost.expired_at #=\u003e 2019-12-06 04:58:19 +0000\n```\n\n##### each class\n\npost.json\n```json\n{\n  \"title\": \"Ruson\",\n  \"tags\": [\n    {\n      \"name\": \"Ruby\"\n    },\n    {\n      \"name\": \"Json\"\n    }\n   ]\n}\n```\n\n```ruby\nrequire 'ruson'\n\nclass Post \u003c Ruson::Base\n  field :title\n  field :tags, each_class: Tag\nend\n\nclass Tag \u003c Ruson::Base\n  field :name\nend\n\njson = File.read('post.json')\npost = Post.new(json)\npost.tags.first.name #=\u003e 'Ruby'\n```\n\n#### enum\n\narticle.json\n```json\n{  \n   \"title\":\"Title\",\n   \"status\":\"draft\"\n}\n```\n\n```ruby\nclass Article \u003c Ruson::Base\n  field :title\n  enum status: { :draft, :published }\nend\n\narticle = Article.new('article.json')\n\narticle.status #=\u003e :draft\narticle.draft? #=\u003e true\n\narticle.status = 'published'\narticle.status #=\u003e :published\n\narticle.status = 'undefined'\n  #=\u003e undefined is not a valid status (ArgumentError)\n```\n\n#### to_json\n\n```ruby\nclass Post \u003c Ruson::Base\n  field :title\n  field :url\nend\n\njson = File.read('post.json')\npost = Post.new(json)\npost.url = 'https://example.com/examples'\n\npost.to_json #=\u003e \"{\\\"title\\\":\\\"Ruson\\\",\\\"url\\\":\\\"https://example.com/examples\\\"}\"\n```\n\n#### to_hash\n\n```ruby\nclass Post \u003c Ruson::Base\n  field :title\n  field :url\nend\n\njson = File.read('post.json')\npost = Post.new(json)\npost.url = 'https://example.com/examples'\n\npost.to_hash #=\u003e {title: \"Ruson\", url: \"https://example.com/examples\" }\n```\n\n#### API json parser\n\n```ruby\nclass Article \u003c Ruson::Base\n  field :title\n  field :description\nend\n\nconn = Faraday::Connection.new(url: 'https://your.api/articles/1') do |faraday|\n  faraday.request :url_encoded\n  faraday.adapter Faraday.default_adapter\nend\n\nresponse = conn.get\narticle = Article.new(response.body)\narticle.title\n```\n\n### Persistence\n\nPersistence will save the models as JSON file, with the model ID as filename, and model class name as parent folder so that a `User` model with ID `1` will be saved as `Users/1.json`.\n\nYou *must* define the `output_folder` before to be able to call `save` or `destroy`.\n\n```ruby\nRuson.output_folder = './db/'\n```\n\n#### Creating new record\n\n```ruby\nclass User \u003c Ruson::Base\n  field :first_name\n  field :last_name\n  field :email\n  field :title\nend\n\n# Using new + save\nguillaume = User.new(first_name: 'Guillaume', last_name: 'Briat', email: 'guillaume@kaamelott.fr')\nguillaume.save # Creates the ./db/Users/1.json file\n\n# Or using the create method\nguillaume = User.create(first_name: 'Guillaume', last_name: 'Briat', email: 'guillaume@kaamelott.fr')\n\nputs File.read('./db/Users/1.json')\n{\"first_name\":\"Guillaume\",\"last_name\":\"Briat\",\"email\":\"guillaume@kaamelott.fr\"}\n=\u003e nil\n```\n\n#### Updating a record\n\n```ruby\n# Assigning a value + save\nguillaume.title = 'Burgundians King'\nguillaume.save # Updates the ./db/Users/1.json file\n\n# Or using the update method\nguillaume.update(title: 'Burgundians King')\n\nputs File.read('./db/Users/1.json')\n{\"first_name\":\"Guillaume\",\"last_name\":\"Briat\",\"email\":\"guillaume@kaamelott.fr\",\"title\":\"Burgundians King\"}\n=\u003e nil\n```\n\n#### Destroying a record\n\n```ruby\nguillaume.destroy # Deletes the ./db/Users/1.json file\n\nputs File.read('./db/Users/1.json')\nTraceback (most recent call last):\n       16: from /usr/local/bundle/gems/bundler-2.0.2/exe/bundle:30:in `block in \u003ctop (required)\u003e'\n       ...\n        2: from (irb):26\n        1: from (irb):26:in `read'\nErrno::ENOENT (No such file or directory @ rb_sysopen - ./db/Users/1.json)\n```\n\n### Querying\n\nRuson allows you to query for existing records.\n\nYou *must* define the `output_folder` before to query records.\n\n```ruby\nRuson.output_folder = './db/'\n```\n\n#### Find a record by ID\n\n```ruby\nUser.find(1) # Searches for a ./db/Users/1.json file\n\n# Searching a user which doesn't exist\nUser.find(1234) #=\u003e nil\nUser.find!(1234) #=\u003e raises Ruson::RecordNotFound\n```\n\n#### Find first record\n\n```ruby\nUser.first # Loads the first ./db/Users/*.json file.\n\n# Without existing User records\nUser.first #=\u003e nil\nUser.first! #=\u003e raises Ruson::RecordNotFound\n```\n\n#### Find a record by attributes\n\npost.json\n\n```json\n{\n  \"title\": \"Ruson\",\n  \"content\": \"Welcome!\"\n}\n```\n\n```ruby\nPost.create(File.read('post.json'))\n```\n\n```ruby\nPost.where(title: 'Ruson')\n#=\u003e [#\u003cPost:0x000055bb2e907b78 @title=\"Ruson\", @content=\"Welcome!\", @id=1\u003e]\n\nPost.where(content: 'Wel')\n#=\u003e []\n\nPost.where(content: 'Welcome!')\n#=\u003e [#\u003cPost:0x000055bb2e907b78 @title=\"Ruson\", @content=\"Welcome!\", @id=1\u003e]\n\nPost.where(title: 'Ruson', content: 'Welcome!')\n#=\u003e [#\u003cPost:0x000055bb2e907b78 @title=\"Ruson\", @content=\"Welcome!\", @id=1\u003e]\n```\n\n## Development\n\n### Without Docker\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### With Docker\n\n```\n$ docker build -t `whoami`/ruson .\n```\n\nIn order to see the available Rake tasks:\n\n```\n$ docker --rm `whoami`/ruson\nrake build            # Build ruson-1.2.0.gem into the pkg directory\nrake clean            # Remove any temporary products\nrake clobber          # Remove any generated files\nrake install          # Build and install ruson-1.2.0.gem into system gems\nrake install:local    # Build and install ruson-1.2.0.gem into system gems without network access\nrake release[remote]  # Create tag v1.2.0 and build and push ruson-1.2.0.gem to rubygems.org\nrake spec             # Run RSpec code examples\n```\n_`--rm` means delete the container after the command has ended._\n\nIn order to execute the tests:\n\n```\n$ docker run --rm -it --volume \"$PWD\":/gem/ `whoami`/ruson rake spec\n```\n_`--volume` is used to sync the files from your current folder into the container so that if you change a file, the modification is available in the container._\n\nIn the case you'd like to access the IRB console:\n\n```\n$ docker run --rm -it --volume \"$PWD\":/gem/ `whoami`/ruson irb\nirb(main):001:0\u003e require 'ruson'\n=\u003e true\nirb(main):002:0\u003e\n```\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/klriutsa/ruson. 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## Code Status\n\n[![Build Status](https://travis-ci.org/klriutsa/ruson.svg?branch=master)](https://travis-ci.org/klriutsa/ruson)\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the Ruson project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/ruson/blob/master/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubyonworld%2Fruson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frubyonworld%2Fruson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubyonworld%2Fruson/lists"}