Jason
JSON encode/decode library written in Erlang
Install / Use
/learn @crownedgrouse/JasonREADME
jason 
jason is a JSON encode/decode library written in Erlang.
DEPRECATION NOTE: as a JSON library is now part of ERLANG/OTP, this library will be replaced by another in close future.
json library will be used instead for parsing, encoding and decoding, but features will be kept. A new name will be chosen in order to be less confusing with the Elixir eponym library.
Overview
This project was mainly created for easy handling of JSON from/to Erlang records, but allow binary struct, proplists and maps formats.
Project is available on hex.pm under name jason_erl.
jason offer also a rare feature : pretty printing JSON in several indentation styles.
See Wiki for documentation and tutorial.
Specifications
- Pure Erlang (no NIF)
- Decoding use Leex/Yecc parser
- JSON object can be decoded in several formats :
- binary struct
- proplists
- maps
- records with automatic ad hoc module loaded for record handling
- No
parse_transform. Record definitions can be given as arguments or extracted from module(s) abstract code at runtime.
Data types
jason:types/0 show in console how Erlang types are converted to JSON and back to Erlang data.
1> jason:types().
Erlang JSON Erlang
================================================================================
%% Atoms
null -> null -> null
undefined -> null -> null
true -> true -> true
false -> false -> false
any -> "any" -> <<"any">>
%% Integer
123 -> 123 -> 123
%% Float (Automatic precision)
123.456789 -> 123.456789 -> 123.456789
2.30e+0 -> 2.3 -> 2.3
2.30e+3 -> 2300.0 -> 2.3e3
2.30e-3 -> 0.0023 -> 0.0023
%% List
[1,2,3] -> [1,2,3] -> [1,2,3]
[a,"b",<<"c">>] -> ["a","b","c"] -> [<<"a">>,<<"b">>,<<"c">>]
%% Date
{{1970,1,1},{0,0,0}} -> "1970-01-01T00:00:00Z" -> {{1970,1,1},
{0,0,0}}
{{1970,1,1},{0,0,0.0}} -> "1970-01-01T00:00:00.000Z" -> {{1970,1,1},
{0,0,0.0}}
%% Binary (key/value) mode=struct (default)
<<"abc">> -> "abc" -> <<"abc">>
%% Struct
% mode=struct (default)
{<<"abc">>,<<"def">>} -> {"abc": "def"} -> [{<<"abc">>,<<"def">>}]
% mode=proplist
{<<"abc">>,<<"def">>} -> {"abc": "def"} -> [{abc,"def"}]
% mode=map
{<<"abc">>,<<"def">>} -> {"abc": "def"} -> #{abc => "def"}
% mode=record
{<<"abc">>,<<"def">>} -> {"abc": "def"} -> {'111259705',"def"}
with -record('111259705', {abc = [] :: list()}).
%% Proplist
% mode=struct (default)
[{abc,<<"def">>}] -> {"abc": "def"} -> [{<<"abc">>,<<"def">>}]
% mode=proplist
[{abc,<<"def">>}] -> {"abc": "def"} -> [{abc,"def"}]
% mode=map
[{abc,<<"def">>}] -> {"abc": "def"} -> #{abc => "def"}
% mode=record
[{abc,<<"def">>}] -> {"abc": "def"} -> {'111259705',"def"}
with -record('111259705', {abc = [] :: list()}).
%% Map
% mode=struct (default)
#{"abc" => <<"def">>} -> {"abc": "def"} -> [{<<"abc">>,<<"def">>}]
% mode=proplist
#{"abc" => <<"def">>} -> {"abc": "def"} -> [{abc,"def"}]
% mode=map
#{"abc" => <<"def">>} -> {"abc": "def"} -> #{abc => "def"}
% mode=record
#{"abc" => <<"def">>} -> {"abc": "def"} -> {'111259705',"def"}
with -record('111259705', {abc = [] :: list()}).
%% Record - encoding using option [{records, [{r, record_info(fields, r)}]}] or [{records, [{r, [k1,k2]}]}]
% mode=struct (default)
{r,1,<<"ab">>} -> {"k1": 1,"k2": "ab"} -> [{<<"k1">>,1},
{<<"k2">>,<<"ab">>}]
% mode=proplist
{r,1,<<"ab">>} -> {"k1": 1,"k2": "ab"} -> [{k1,1},{k2,"ab"}]
% mode=map
{r,1,<<"ab">>} -> {"k1": 1,"k2": "ab"} -> #{k1 => 1,k2 => "ab"}
% mode=record
{r,1,<<"ab">>} -> {"k1": 1,"k2": "ab"} -> {'8056669',1,"ab"}
with -record('8056669', {k1 = 0 :: integer(), k2 = [] :: list()}).
% mode=record - decoding using option [{records, [{r, [k1,k2]}]}]
-> {r,1,"ab"}
Related Skills
node-connect
352.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
111.1kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
352.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
352.0kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
