Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/meh/jazz
Yet another library to handle JSON in Elixir.
https://github.com/meh/jazz
Last synced: 23 days ago
JSON representation
Yet another library to handle JSON in Elixir.
- Host: GitHub
- URL: https://github.com/meh/jazz
- Owner: meh
- Created: 2013-07-14T01:16:24.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2018-07-10T17:25:37.000Z (over 6 years ago)
- Last Synced: 2024-05-11T18:44:58.267Z (8 months ago)
- Language: Elixir
- Size: 78.1 KB
- Stars: 61
- Watchers: 7
- Forks: 21
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- freaking_awesome_elixir - Elixir - Yet another library to handle JSON in Elixir. (JSON)
- fucking-awesome-elixir - jazz - Yet another library to handle JSON in Elixir. (JSON)
- awesome-elixir - jazz - Yet another library to handle JSON in Elixir. (JSON)
README
jazz - JSON handling library for Elixir
=======================================
Jazz is a JSON handling library written in Elixir, for Elixir.Examples
--------```elixir
use JazzJSON.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
endJSON.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
enddefimpl JSON.Decoder, for: HashDict do
def decode(_new, parsed, _options) do
parsed |> Enum.into(HashDict.new)
end
endJSON.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" }]>
```