Popularity
7.9
Stable
Activity
0.0
Stable
219
9
40

Monthly Downloads: 28,891
Programming language: Elixir
License: BSD 3-clause "New" or "Revised" License
Tags: JSON    
Latest version: v1.3.0

json alternatives and similar packages

Based on the "JSON" category.
Alternatively, view json alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of json or a related project?

Add another 'JSON' Package

README

Elixir JSON

Build Status Hex.pm Coverage Status Inline docs

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

You can find the package in hex.pm and the documentation in hexdocs.pm.

All contributions are welcome!

Installing

Simply add {:json, "~> 1.4"} to your project's mix.exs and run mix deps.get.

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"

At any time, you can turn on verbose logging for this library only. To do so, head to config file of your application and add below lines:

use Mix.Config

config :logger, level: :debug

config :json, log_level: :debug

Note that, changing only :logger level to :info, :warn or :error will silent :json too.

License

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


*Note that all licence references and agreements mentioned in the json README section above are relevant to that project's source code only.