Skip to content

Instantly share code, notes, and snippets.

@doomspork
Created January 22, 2016 22:35
Show Gist options
  • Save doomspork/2ef57a74c84330b1239b to your computer and use it in GitHub Desktop.
Save doomspork/2ef57a74c84330b1239b to your computer and use it in GitHub Desktop.
defmodule Example.User do
@derive [Poison.Encoder]
defstruct [:name, :age]
end
iex> json = ~s({"name": "uto", "age": "old"})
"{\"name\": \"uto\", \"age\": \"old\"}"
iex> Poison.decode!(json, as: Example.User)
%Example.User{age: "old", name: "uto"}
iex> Poison.encode!(%Example.User{age: "old", name: "uto"})
"{\"name\":\"uto\",\"age\":\"old\"}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment