Skip to content
Native JSON library for Elixir
Elixir
Latest commit 848f564 Jun 22, 2016 @cblage committed on GitHub Merge pull request #41 from danturn/master
removing warnings

README.md

Elixir JSON

Build Status

This library provides a natively implemented JSON encoder and decoder for Elixir.

All contributions are welcome.

Installing

Simply add {:json, "~> 0.3.0"} to your project's mix.exs file, in the dependencies list and run mix deps.get json.

Example for a project that already uses Dynamo:

defp deps do
    [ { :cowboy, "~> 1.0.0" },
      { :dynamo, github: "dynamo/dynamo" },
      { :json,   "~> 0.3.0"} ]
end

Usage

Encoding an Elixir type

  @doc "
    JSON encode an Elixir list
  " 
  list = [key: "this will be a value"]
  is_list(list)
  # true
  list[:key]
  # "this will be a value"
  {status, result} = JSON.encode(list)
  # {:ok, "{\"key\":\"this will be a value\"}"}
  String.length(result)
  # 41

Decoding a list from a string that contains JSON

  @doc "
    JSON decode a string into an Elixir list
  "
  json_input = "{\"key\":\"this will be a value\"}"
  {status, list} = JSON.decode(json_input)
    {:ok, %{"key" => "this will be a value"}}
  list[:key]
  # nil
  list["key"]
  # "this will be a value"

License

The Elixir JSON library is available under the BSD 3-Clause aka "BSD New" license

Something went wrong with that request. Please try again.