{"id":16484897,"url":"https://github.com/stephenmoloney/mapail","last_synced_at":"2025-08-17T12:32:30.901Z","repository":{"id":57520625,"uuid":"59896475","full_name":"stephenmoloney/mapail","owner":"stephenmoloney","description":"Convert maps with string keys to an elixir struct with Mapáil.","archived":false,"fork":false,"pushed_at":"2017-04-28T17:49:19.000Z","size":29,"stargazers_count":4,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-18T20:22:23.187Z","etag":null,"topics":["conversion","elixir","elixir-lang","json","maps","struct"],"latest_commit_sha":null,"homepage":"https://hex.pm/packages/mapail","language":"Elixir","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/stephenmoloney.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-05-28T13:41:53.000Z","updated_at":"2018-08-18T21:56:18.000Z","dependencies_parsed_at":"2022-09-26T18:00:30.815Z","dependency_job_id":null,"html_url":"https://github.com/stephenmoloney/mapail","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephenmoloney%2Fmapail","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephenmoloney%2Fmapail/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephenmoloney%2Fmapail/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephenmoloney%2Fmapail/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stephenmoloney","download_url":"https://codeload.github.com/stephenmoloney/mapail/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245104464,"owners_count":20561376,"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":["conversion","elixir","elixir-lang","json","maps","struct"],"created_at":"2024-10-11T13:18:39.020Z","updated_at":"2025-03-23T12:32:40.565Z","avatar_url":"https://github.com/stephenmoloney.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mapáil [![Build Status](https://travis-ci.org/stephenmoloney/mapail.svg)](https://travis-ci.org/stephenmoloney/mapail) [![Hex Version](http://img.shields.io/hexpm/v/mapail.svg?style=flat)](https://hex.pm/packages/mapail) [![Hex docs](http://img.shields.io/badge/hex.pm-docs-green.svg?style=flat)](https://hexdocs.pm/mapail)\n\nHelper library to convert a map into a struct or a struct to a struct.\n\n\n## Features\n\n\n- String keyed maps: Convert maps with string keys to a corresponding struct.\n\n- Transformations: Optionally, string manipulations can be applied to the key of the map so as to attempt to\nforce the key to match the key of the struct. Currently, the only transformation option is conversion to snake_case.\n\n- Residual maps: Optionally, the part of the map leftover after the struct has been built can be retrieved\nor merged back into the returned struct.\n\n- Helper function for converting atom-keyed maps or string/atom mixed keyed maps to string-keyed only maps.\n\n- Helper function for converting a struct to another struct.\n\n\n## Examples\n\n\n#### Example - exact key matching (no transformations)\n\n```elixir\ndefmodule User do\n  defstruct [:first_name, :username, :password]\nend\n\nuser = %{\n  \"FirstName\" =\u003e \"John\",\n  \"Username\" =\u003e \"john\",\n  \"password\" =\u003e \"pass\",\n  \"age\" =\u003e 30\n}\n\nMapail.map_to_struct(user, User)\n\n{:ok, %User{\n  first_name: :nil,\n  username: :nil,\n  password: \"pass\"\n  }\n}\n```\n\n\n#### Example - key matching with `transformations: [:snake_case]`\n\n```elixir\ndefmodule User do\n  defstruct [:first_name, :username, :password]\nend\n\nuser = %{\n  \"FirstName\" =\u003e \"John\",\n  \"Username\" =\u003e \"john\",\n  \"password\" =\u003e \"pass\",\n  \"age\" =\u003e 30\n}\n\nMapail.map_to_struct(user, User, transformations: [:snake_case])\n\n{:ok, %User{\n  first_name: \"John\",\n  username: \"john\",\n  password: \"pass\"\n  }\n}\n```\n\n#### Example - getting unmatched elements in a separate map\n\n```elixir\ndefmodule User do\n  defstruct [:first_name, :username, :password]\nend\n\nuser = %{\n  \"FirstName\" =\u003e \"John\",\n  \"Username\" =\u003e \"john\",\n  \"password\" =\u003e \"pass\",\n  \"age\" =\u003e 30\n}\n\n{:ok, user_struct, leftover} = Mapail.map_to_struct(user, User, rest: :true)\n\n\n{:ok, %User{\n  first_name: :nil,\n  username: \"pass\",\n  password: :nil\n  },\n  %{\n    \"FirstName\" =\u003e \"John\",\n    \"Username\" =\u003e \"john\",\n    \"age\" =\u003e 30\n  }\n}\n```\n\n#### Example - getting unmatched elements in a merged nested map\n\n```elixir\ndefmodule User do\n  defstruct [:first_name, :username, :password]\nend\n\nuser = %{\n  \"FirstName\" =\u003e \"John\",\n  \"Username\" =\u003e \"john\",\n  \"password\" =\u003e \"pass\",\n  \"age\" =\u003e 30\n}\n\nMapail.map_to_struct(user, User, rest: :merge)\n\n{:ok, %User{\n  first_name: :nil,\n  username: \"pass\",\n  password: :nil,\n  mapail: %{\n    \"FirstName\" =\u003e \"John\",\n    \"Username\" =\u003e \"john\",\n    \"age\" =\u003e 30\n  }\n}\n```\n\n\n## Documentation\n\n- [Documentation](https://hex.pm/packages/mapail) can be found in the hex package manager.\n\n\n## Installation\n\nThe package can be installed as follows:\n\n1. Add mapail to your list of dependencies in `mix.exs`:\n\n```\ndef deps do\n  [{:mapail, \"~\u003e 1.0\"}]\nend\n```\n\n2. Ensure mapail is started before your application:\n\n```\ndef application do\n  [applications: [:mapail]]\nend\n```\n\nThe package can be found in [hex](https://hex.pm/packages/mapail).\n\n\n## Credit\n\nThis library depends on the following library:\n- [Maptu](https://hex.pm/packages/maptu) v1.0.0 library. For converting a matching map to a struct.\nMIT © 2016 Andrea Leopardi, Aleksei Magusev. [Licence](https://github.com/lexhide/maptu/blob/master/LICENSE.txt)\n\n\n## Licence\n\n[MIT Licence](LICENSE.txt)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstephenmoloney%2Fmapail","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstephenmoloney%2Fmapail","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstephenmoloney%2Fmapail/lists"}