{"id":13879228,"url":"https://github.com/visualitypl/jsonapi_parameters","last_synced_at":"2025-08-10T08:04:13.603Z","repository":{"id":47845101,"uuid":"165895294","full_name":"visualitypl/jsonapi_parameters","owner":"visualitypl","description":"Rails-way to consume JSON:API input","archived":false,"fork":false,"pushed_at":"2022-07-19T18:16:43.000Z","size":148,"stargazers_count":60,"open_issues_count":7,"forks_count":8,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-07-28T00:02:26.591Z","etag":null,"topics":["api","json","json-api","jsonapi","rails","ruby","ruby-on-rails"],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/jsonapi_parameters","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/visualitypl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-01-15T17:37:27.000Z","updated_at":"2025-05-26T19:41:33.000Z","dependencies_parsed_at":"2022-08-20T23:10:46.415Z","dependency_job_id":null,"html_url":"https://github.com/visualitypl/jsonapi_parameters","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/visualitypl/jsonapi_parameters","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/visualitypl%2Fjsonapi_parameters","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/visualitypl%2Fjsonapi_parameters/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/visualitypl%2Fjsonapi_parameters/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/visualitypl%2Fjsonapi_parameters/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/visualitypl","download_url":"https://codeload.github.com/visualitypl/jsonapi_parameters/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/visualitypl%2Fjsonapi_parameters/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269693593,"owners_count":24460248,"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-08-10T02:00:08.965Z","response_time":71,"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":["api","json","json-api","jsonapi","rails","ruby","ruby-on-rails"],"created_at":"2024-08-06T08:02:14.230Z","updated_at":"2025-08-10T08:04:13.579Z","avatar_url":"https://github.com/visualitypl.png","language":"Ruby","readme":"# JsonApi::Parameters\nSimple [JSON:API](https://jsonapi.org/) compliant parameters translator.\n\n[![Gem Version](https://badge.fury.io/rb/jsonapi_parameters.svg)](https://badge.fury.io/rb/jsonapi_parameters)\n[![Maintainability](https://api.codeclimate.com/v1/badges/84fd5b548eea8d7e18af/maintainability)](https://codeclimate.com/github/visualitypl/jsonapi_parameters/maintainability)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/84fd5b548eea8d7e18af/test_coverage)](https://codeclimate.com/github/visualitypl/jsonapi_parameters/test_coverage)\n[![CircleCI](https://circleci.com/gh/visualitypl/jsonapi_parameters.svg?style=svg)](https://circleci.com/gh/visualitypl/jsonapi_parameters)\n\n[Documentation](https://github.com/visualitypl/jsonapi_parameters/wiki)\n\n## Usage\n\n### Installation\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'jsonapi_parameters'\n```\n\nAnd then execute:\n\n```bash\n$ bundle\n```\n\nOr install it yourself as:\n\n```bash\n$ gem install jsonapi_parameters\n```\n\n### Rails\n\nUsually your strong parameters in controller are invoked this way:\n\n```ruby\ndef create\n  model = Model.new(create_params)\n  \n  if model.save\n    ...\n  else\n    head 500\n  end\nend\n\nprivate\n\ndef create_params\n  params.require(:model).permit(:name)\nend\n```\n\nWith jsonapi_parameters, the difference is just the params:\n\n```ruby\ndef create_params\n  params.from_jsonapi.require(:model).permit(:name)\nend\n```\n\n#### Relationships\n\nJsonApi::Parameters supports ActiveRecord relationship parameters, including [nested attributes](https://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html).\n\nRelationship parameters are being read from two optional trees:  \n\n* `relationships`,\n* `included`\n\nIf you provide any related resources in the `relationships` table, this gem will also look for corresponding, `included` resources and their attributes. Thanks to that this gem supports nested attributes, and will try to translate these included resources and pass them along.\n\nFor more examples take a look at [Relationships](https://github.com/visualitypl/jsonapi_parameters/wiki/Relationships) in the wiki documentation.\n\n\n### Plain Ruby / outside Rails\n\n```ruby\n\nparams = { # JSON:API compliant parameters here\n\t# ...\n}\n\nclass Translator\n  include JsonApi::Parameters\nend\ntranslator = Translator.new\n\ntranslator.jsonapify(params)\n```\n \n## Mime Type\n\nAs [stated in the JSON:API specification](https://jsonapi.org/#mime-types) correct mime type for JSON:API input should be [`application/vnd.api+json`](http://www.iana.org/assignments/media-types/application/vnd.api+json). \n\nThis gem's intention is to make input consumption as easy as possible. Hence, it [registers this mime type for you](lib/jsonapi_parameters/core_ext/action_dispatch/http/mime_type.rb).\n\n## Stack limit\n\nIn theory, any payload may consist of infinite amount of relationships (and so each relationship may have its own, included, infinite amount of nested relationships).\nBecause of that, it is a potential vector of attack. \n\nFor this reason we have introduced a default limit of stack levels that JsonApi::Parameters will go down through while parsing the payloads. \n\nThis default limit is 3, and can be overwritten by specifying the custom limit.\n\n#### Ruby\n```ruby\nclass Translator\n    include JsonApi::Parameters\nend\n\ntranslator = Translator.new\n\ntranslator.jsonapify(custom_stack_limit: 4)\n\n# OR\n \ntranslator.stack_limit = 4\ntranslator.jsonapify.(...)\n``` \n\n#### Rails\n```ruby\ndef create_params\n    params.from_jsonapi(custom_stack_limit: 4).require(:user).permit(\n        entities_attributes: { subentities_attributes: { ... } }\n    )\nend\n\n# OR\n \ndef create_params\n    params.stack_level = 4\n\n    params.from_jsonapi.require(:user).permit(entities_attributes: { subentities_attributes: { ... } })\nensure\n    params.reset_stack_limit!\nend\n```\n\n## Customization\n\nIf you need custom relationship handling (for instance, if you have a relationship named `scissors` that is plural, but it actually is a single entity), you can use Handlers to define appropriate behaviour.\n\nRead more at [Relationship Handlers](https://github.com/visualitypl/jsonapi_parameters/wiki/Relationship-handlers).\n\n## Team\n\nProject started by [Jasiek Matusz](https://github.com/Marahin).\n\nCurrently, jsonapi_parameters is maintained by Visuality's [Open Source Commitee](https://www.visuality.pl/open-source).\n\n## License\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","funding_links":[],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvisualitypl%2Fjsonapi_parameters","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvisualitypl%2Fjsonapi_parameters","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvisualitypl%2Fjsonapi_parameters/lists"}