项目
在 GitHub 查看
cblage/elixir-json
关于
Elixir 原生 JSON 库
开发工具实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- 0
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文Elixir JSON
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
探索相关项目
加载中…