{"id":14955628,"url":"https://github.com/64kramsystem/json_on_rails","last_synced_at":"2025-11-11T18:38:21.286Z","repository":{"id":56887234,"uuid":"121058958","full_name":"64kramsystem/json_on_rails","owner":"64kramsystem","description":"MySQL JSON support for Rails 4","archived":false,"fork":false,"pushed_at":"2019-09-19T17:44:32.000Z","size":49,"stargazers_count":16,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-16T04:16:35.780Z","etag":null,"topics":["json","json-columns","mysql","rails","rails4","ruby"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/64kramsystem.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-10T22:13:42.000Z","updated_at":"2025-08-06T07:27:56.000Z","dependencies_parsed_at":"2022-08-20T16:00:12.127Z","dependency_job_id":null,"html_url":"https://github.com/64kramsystem/json_on_rails","commit_stats":null,"previous_names":["saveriomiroddi/json_on_rails"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/64kramsystem/json_on_rails","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/64kramsystem%2Fjson_on_rails","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/64kramsystem%2Fjson_on_rails/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/64kramsystem%2Fjson_on_rails/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/64kramsystem%2Fjson_on_rails/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/64kramsystem","download_url":"https://codeload.github.com/64kramsystem/json_on_rails/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/64kramsystem%2Fjson_on_rails/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":283910127,"owners_count":26915128,"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","status":"online","status_checked_at":"2025-11-11T02:00:06.610Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["json","json-columns","mysql","rails","rails4","ruby"],"created_at":"2024-09-24T13:11:28.148Z","updated_at":"2025-11-11T18:38:21.268Z","avatar_url":"https://github.com/64kramsystem.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/saveriomiroddi/json_on_rails.svg?branch=master)](https://travis-ci.org/saveriomiroddi/json_on_rails)\n[![Coverage Status](https://coveralls.io/repos/github/saveriomiroddi/json_on_rails/badge.svg?branch=master)](https://coveralls.io/github/saveriomiroddi/json_on_rails?branch=master)\n\n# JSON on Rails\n\nThis gem adds native support for MySQL [5.7+] JSON data type to Rails 4.2.\n\n## Introduction\n\nRails 5 introduced native support for the [MySQL] JSON data type; however, due to the Rails feature policy, version 4 won't receive this functionality.\n\nThis gem adds a Rails JSON data type, allowing the user to work with JSON attributes transparently, as a Array/Hash/etc.\n\nThe inner working is simple, and uses the standard Rails (internal) APIs; this is explained in a [blog post of mine](https://saveriomiroddi.github.io/Support-MySQL-native-JSON-data-type-in-Rails-4).\n\n## Installation\n\nAdd the gem to the Gemfile of your rails project:\n\n```ruby\ngem \"json_on_rails\", \"~\u003e 0.2.0\"\n```\n\nand update the environment:\n\n```sh\n$ bundle install\n```\n\nChange the `mysql` connection adapter to `mysql2_json`, in `config/database.yml`:\n\n```yaml\ndefault: \u0026default\n  adapter: mysql2_json\n```\n\nthat's all!\n\n## Usage/example\n\nCreate a table:\n\n```\nclass CreateUsers \u003c ActiveRecord::Migration\n  def change\n    create_table \"migration_models\" do |t|\n      t.string \"login\", null: false, limit: 24\n      t.json \"extras\"\n    end\n  end\nend\n```\n\nor add the column to an existing one:\n\n```\nclass CreateUsers \u003c ActiveRecord::Migration\n  def change\n    add_column \"users\", \"extras\", :json\n  end\nend\n```\n\ndefine the model (rails will automatically pick up the data type):\n\n```\nclass User \u003c ActiveRecord::Base; end\n```\n\nthen (ab)use the new attribute!:\n\n```ruby\nUser.create!(login: \"saverio\", extras: {\"uses\" =\u003e [\"mysql\", \"json\"]})\n# ...\nUser.last.extras.fetch(\"uses\") # =\u003e [\"mysql\", \"json\"]\n```\n\nThe schema can be dumped as usual; json columns will be transparently included:\n\n```sh\n$ rake db:schema:dump\n$ cat db/schema.rb\nActiveRecord::Schema.define(version: 0) do\n\n  create_table \"users\", force: :cascade do |t|\n    t.json   \"extras\"\n  end\n\nend\n```\n\n## Caveats/further documentation\n\n### MySQL SELECT DISTINCT JSON bug (**IMPORTANT!**)\n\nMySQL versions up to at least 5.7.12 have a serious JSON bug.\n\nIn some cases, queries using DISTINCT on VARCHAR and JSON columns will not perform the deduplication, resulting in duplicate rows being returned, if there are any.\n\nThis has been fixed between 5.7.13 and 5.7.18 (I couldn't find the related enty in the release notes), therefore, MySQL 5.7 users are urged to upgrade to a recent version if they use JSON columns.\n\n### Documentation\n\nUsers are encouraged to have a look at the test suite (especially [here](spec/json_on_rails/json_attributes_spec.rb) and [here](spec/json_on_rails/arel_methods_spec.rb)) for an exhaustive view of the functionality.\n\n### JSON Symbols\n\nDon't forget that JSON doesn't support symbols, therefore, they can be set, but are accessed/loaded as strings.\n\n### MySQL decimal normalization\n\nMySQL (up to 8.0.3, included) will normalize decimal numbers with zero fractional (e.g. `5.0`) to integers, therefore, changing the data type on save.\n\nSee [relevant bug](https://bugs.mysql.com/bug.php?id=88230).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F64kramsystem%2Fjson_on_rails","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F64kramsystem%2Fjson_on_rails","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F64kramsystem%2Fjson_on_rails/lists"}