{"id":15288771,"url":"https://github.com/spickermann/deep_hash_transformer","last_synced_at":"2025-07-26T10:15:20.687Z","repository":{"id":20334108,"uuid":"89567076","full_name":"spickermann/deep_hash_transformer","owner":"spickermann","description":"DeepHashTransformer helps to transform deeply nested hash structures","archived":false,"fork":false,"pushed_at":"2025-07-22T13:42:24.000Z","size":47,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-22T15:25:26.805Z","etag":null,"topics":["gem","hash","rails","ruby","transformations"],"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/spickermann.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"MIT-LICENSE","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":"2017-04-27T07:11:05.000Z","updated_at":"2025-07-22T13:42:27.000Z","dependencies_parsed_at":"2024-03-11T17:02:08.888Z","dependency_job_id":"9f89462f-d8c5-4a07-bab7-6a14edfcdd64","html_url":"https://github.com/spickermann/deep_hash_transformer","commit_stats":{"total_commits":38,"total_committers":4,"mean_commits":9.5,"dds":"0.13157894736842102","last_synced_commit":"c41b3a9f4f3ccd2261b7a6737a05adf4397b7d1c"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/spickermann/deep_hash_transformer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spickermann%2Fdeep_hash_transformer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spickermann%2Fdeep_hash_transformer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spickermann%2Fdeep_hash_transformer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spickermann%2Fdeep_hash_transformer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spickermann","download_url":"https://codeload.github.com/spickermann/deep_hash_transformer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spickermann%2Fdeep_hash_transformer/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266523423,"owners_count":23942784,"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-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"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":["gem","hash","rails","ruby","transformations"],"created_at":"2024-09-30T15:53:08.827Z","updated_at":"2025-07-26T10:15:20.676Z","avatar_url":"https://github.com/spickermann.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DeepHashTransformer\n\nThe `DeepHashTransformer` helps to translate keys in deeply nested hash (and array) structures.\n\nIn opposite to the ActiveSupport's `deep_transform_keys` method `deep_transform_keys` is the `DeepHashTransformer` able to transform keys in hashes that are stored in nested arrays, for example a structure like this `{ foo: [{ bar: 1 }, { bar: 2 }] }`\n\nA good use-case might be the transformation of a JSON API style hash (dasherized string keys) that was returned by an API to a hash that follows common Ruby idioms (symbolized underscore keys), see [Complex Example](#complex-example) below.\n\n[![License MIT](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://github.com/spickermann/deep_hash_transformer/blob/main/MIT-LICENSE)\n[![Gem Version](https://badge.fury.io/rb/deep_hash_transformer.svg)](https://badge.fury.io/rb/deep_hash_transformer)\n[![Build Status](https://github.com/spickermann/deep_hash_transformer/actions/workflows/CI.yml/badge.svg)](https://github.com/spickermann/deep_hash_transformer/actions/workflows/CI.yml)\n[![Codacy Badge](https://app.codacy.com/project/badge/Grade/a3acda9da2a041ffbee1e6ad76e0c02f)](https://app.codacy.com/gh/spickermann/deep_hash_transformer/dashboard)\n[![Codacy Badge](https://app.codacy.com/project/badge/Coverage/a3acda9da2a041ffbee1e6ad76e0c02f)](https://app.codacy.com/gh/spickermann/deep_hash_transformer/dashboard)\n\n## Installation\n\nInclude the gem in your Gemfile:\n\n```ruby\ngem 'deep_hash_transformer'\n```\n\nWhen you are still on Ruby 2.2 – 2.4:\n\n```ruby\ngem 'deep_hash_transformer', '~\u003e 1.0.0'\n```\n\nWhen you are still on Ruby 2.1 or below:\n\n```ruby\ngem 'deep_hash_transformer', '~\u003e 0.1.1'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install deep_hash_transformer\n\n## Usage\n\nThe latest version of the `DeepHashTransformer` has the following key transformation operations implemented:\n\n\u003cdl\u003e\n  \u003cdt\u003e\u003ccode\u003e:camel_case\u003c/code\u003e\u003c/dt\u003e\n  \u003cdd\u003etranslates keys into \u003ccode\u003eCamelCase\u003c/code\u003e, example: \u003ccode\u003e\"foo_bar\" =\u003e \"FooBar\"\u003c/code\u003e\u003c/dd\u003e\n  \u003cdt\u003e\u003ccode\u003e:dasherize\u003c/code\u003e\u003c/dt\u003e\n  \u003cdd\u003etranslates underscores in keys into dashes, example: \"foo_bar\" =\u003e \"foo-bar\"\u003c/dd\u003e\u003c/dd\u003e\n  \u003cdt\u003e\u003ccode\u003e:identity\u003c/code\u003e\u003c/dt\u003e\n  \u003cdd\u003ereturns the keys unchanged\u003c/dd\u003e\n  \u003cdt\u003e\u003ccode\u003e:pascal_case\u003c/code\u003e\u003c/dt\u003e\n  \u003cdd\u003etranslates keys into \u003ccode\u003epascalCase\u003c/code\u003e, example: \u003ccode\u003e\"foo_bar\" =\u003e \"fooBar\"\u003c/code\u003e\u003c/dd\u003e\n  \u003cdt\u003e\u003ccode\u003e:snake_case\u003c/code\u003e\u003c/dt\u003e\n  \u003cdd\u003etranslates keys into \u003ccode\u003esnake_case\u003c/code\u003e, example: \u003ccode\u003e\"FooBar\" =\u003e \"foo_bar\"\u003c/code\u003e\u003c/dd\u003e\n  \u003cdt\u003e\u003ccode\u003e:stringify\u003c/code\u003e\u003c/dt\u003e\n  \u003cdd\u003etranslates symbol keys into strings, example \u003ccode\u003e:fooBar =\u003e \"fooBar\"\u003c/code\u003e\u003c/dd\u003e\n  \u003cdt\u003e\u003ccode\u003e:symbolize\u003c/code\u003e\u003c/dt\u003e\n  \u003cdd\u003etranslates string keys into symbols, example \u003ccode\u003e\"fooBar\" =\u003e :fooBar\u003c/code\u003e\u003c/dd\u003e\n  \u003cdt\u003e\u003ccode\u003e:underscore\u003c/code\u003e\u003c/dt\u003e\n  \u003cdd\u003etranslates dashes in keys into underscores, example: \u003ccode\u003e:foo-bar =\u003e \"foo_bar\"\u003c/code\u003e\u003c/dd\u003e\n  \u003cdt\u003e\u003ccode\u003e:compact\u003c/code\u003e\u003c/dt\u003e\n  \u003cdd\u003eremoves \u003ccode\u003enil\u003c/code\u003e values from the hash, example: \u003ccode\u003e{ a: 1, b: nil } =\u003e { a: 1 }\u003c/code\u003e\u003c/dd\u003e\n  \u003cdt\u003e\u003ccode\u003e:compact_blank\u003c/code\u003e\u003c/dt\u003e\n  \u003cdd\u003eremoves blank values (\u003ccode\u003enil\u003c/code\u003e, \u003ccode\u003efalse\u003c/code\u003e, or empty values) from the hash, example: \u003ccode\u003e{ a: 1, b: '' } =\u003e { a: 1 }\u003c/code\u003e\u003c/dd\u003e\n\u003c/dl\u003e\n\nAll transformations can be called by their names, for example:\n\n```ruby\nDeepHashTransformer.new({ foo_bar: 'baz' }).dasherize\n#=\u003e { 'foo-bar' =\u003e 'baz' }\n```\n\nOr you can use `tr` to chain multiple transformations:\n\n```ruby\nDeepHashTransformer.new({ 'foo-bar' =\u003e 'baz' }).tr(:underscore, :symbolize)\n#=\u003e { foo_bar: 'baz' }\n```\n\nIt is worth noting that the `DeepHashTransformer` only transforms string or symbol keys and leaves all other types untouched:\n\n```ruby\nDeepHashTransformer.new({ 1 =\u003e 'foo', :bar =\u003e 'bar', Object =\u003e 'baz' }).stringify\n#=\u003e { 1 =\u003e 'foo', 'bar' =\u003e 'bar', Object =\u003e 'baz' }\n```\n\nAll transformations apart from `symbolize` return per default hashes with stringify keys. When you want to have symbolized keys to be returned, then use `tr` to chain your required transformation with `:symbolize`\n\n## Complex Example\n\n`DeepHashTransformer` transforms all hash keys – even if the key is nested in another hash or stored in a nested array. This is its biggest advantage over ActiveSupport's `deep_transform_keys` method, which is not able to handle hashes in nested arrays.\n\nExample: Transformation of a JSON API style hash (dasherized string keys) to a hash that follows common Ruby idioms (symbolized underscore keys).\n\n```ruby\njson_api_style = {\n  'nested-array' =\u003e [\n    { 'a-key' =\u003e 'a-value', 'b-key' =\u003e nil }\n  ],\n  'foo_bar' =\u003e 'baz'\n}\n\nDeepHashTransformer.new(json_api_style).tr(:underscore, :symbolize, :compact)\n#=\u003e {\n#     nested_array: [\n#       { a_key: 'a-value' }\n#     ],\n#     foo_bar: 'baz'\n#   }\n```\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/spickermann/deep_hash_transformer. 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\n1. [Fork it](http://github.com/spickermann/has_configuration/fork)\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new pull request.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspickermann%2Fdeep_hash_transformer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspickermann%2Fdeep_hash_transformer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspickermann%2Fdeep_hash_transformer/lists"}