frekw
One of the things I’ve missed since coming to Elixir is a simple way to parse data from an external service (like JSON or MessagePack) into a structure that’s more suitable for my application.
I finally got tired of writing transformations from maps with string keys to structs and stole one of Go’s best ideas.
https://github.com/soundtrackyourbrand/forma
Forma parses a typespec that you provide and tries to shape your input data to fit into that typespec.
For example:
defmodule User do
defstruct [:id, :name, :age, :gender]
@type t :: %__MODULE__{
id: String.t,
name: String.t,
age: non_neg_integer(),
gender: :male | :female | :other | :prefer_not_to_say
}
end
Forma.parse(%{"id" => "1", "name" => "Fredrik", "age" => 30, "gender" => "male"}, User)
# => {:ok, %User{id: "1", name: "Fredrik", age: 30, gender: :male}}
It doesn’t do any parsing of its own, but works great together with e.g Poison or jiffy. It supports most cases I’ve stumbled across thus far, but it’s still pretty early in development.
Feedback, ideas for improvements as well as bug reports are welcome!
Trending in Announcing
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries.
offset-based pagination with...
New
I released Doggo, a collection of unstyled Phoenix components.
https://github.com/woylie/doggo
Features
Unstyled Phoenix components....
New
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Hi everyone,
I’ve been working on this protobuf library for 3 years. We use it in the company I work for, EasyMile, to communicate with ...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
I’ll shortly be launching Text, a nascent text analysis library.
Current functionality
In this early version (not ready for prime time) ...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Hey folks,
I just published a post about Hologram’s funding and where the project goes next - the short version:
Curiosum as Main Spons...
New
:microphone: ElixirConf 2026 - Call for Talks is open!
We’re heading to Chicago :united_states:
:round_pushpin: In person + virtual
:d...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex










Showing Posts 1 to 6- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
mischov
Correct me if I’m wrong, but it looks like your examples should be returning
{:ok, %User{...}}tuples instead of just%User{...}?What happens if the input data cannot be parsed to the structure? Does
parsereturns{:error, reason}?frekw
You’re correct, the docs are wrong. I’ll update it!
mischov
In that case, you could probably update
parses spec from@spec parse(input, typeref, parsers) :: anyto
@spec parse(input, typeref, parsers) :: {:ok, any} | {:error, any}.frekw
Ah, completely missed that. Thanks!
stefanluptak
I just found this library and I am wondering why it’s not more popular? I feel like I spend so much time just converting data from JSON to Elixir structs and back. This could really help. I will give it a try.
Phillipp
That whole GitHub org contains quite a lot of nice Elixir packages.