Logo

0x5a.live

for different kinds of informations and explorations.

GitHub - meh/jazz: Yet another library to handle JSON in Elixir.

Yet another library to handle JSON in Elixir. Contribute to meh/jazz development by creating an account on GitHub.

Visit SiteGitHub - meh/jazz: Yet another library to handle JSON in Elixir.

GitHub - meh/jazz: Yet another library to handle JSON in Elixir.

Yet another library to handle JSON in Elixir. Contribute to meh/jazz development by creating an account on GitHub.

Powered by 0x5a.live ๐Ÿ’—

jazz - JSON handling library for Elixir

Jazz is a JSON handling library written in Elixir, for Elixir.

Examples

use Jazz

JSON.encode!(%{name: "David", surname: "Davidson"})
  |> IO.puts # => {"name":"David","surname":"Davidson"}

JSON.decode!(~S/{"name":"David","surname":"Davidson"}/)
  |> IO.inspect # => %{"name" => "David", "surname" => "Davidson"}

JSON.decode!(~S/{"name":"David","surname":"Davidson"}/, keys: :atoms)
  |> IO.inspect # => %{name: "David", surname: "Davidson"}

# would raise if the keys weren't already existing atoms
JSON.decode!(~S/{"name":"David","surname":"Davidson"}/, keys: :atoms!)
  |> IO.inspect # => %{name: "David", surname: "Davidson"}

defmodule Person do
  defstruct name: nil, surname: nil
end

JSON.encode!(%Person{name: "David", surname: "Davidson"})
  |> IO.puts # => {"name":"David","surname":"Davidson"}

JSON.decode!(~S/{"name":"David","surname":"Davidson"}/, as: Person)
  |> IO.inspect # => %Person{name: "David", surname: "Davidson"}

defimpl JSON.Encoder, for: HashDict do
  def encode(self, options) do
    HashDict.to_list(self) |> Enum.into(%{})
  end
end

defimpl JSON.Decoder, for: HashDict do
  def decode(_new, parsed, _options) do
    parsed |> Enum.into(HashDict.new)
  end
end

JSON.encode!(HashDict.new([name: "David", surname: "Davidson"]))
  |> IO.puts # => {"name":"David","surname":"Davidson"}

JSON.decode!(~S/{"name":"David","surname":"Davidson"}/, as: HashDict)
  |> IO.inspect # => #HashDict<[{"name", "David" }, { "surname", "Davidson" }]>

Elixir Resources

are all listed below.

Resources

listed to get explored on!!

Made with โค๏ธ

to provide different kinds of informations and resources.