Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cvik/lejson
Le'Json - Lightweight Erlang Json library
https://github.com/cvik/lejson
Last synced: 2 months ago
JSON representation
Le'Json - Lightweight Erlang Json library
- Host: GitHub
- URL: https://github.com/cvik/lejson
- Owner: cvik
- License: apache-2.0
- Created: 2014-06-03T09:22:47.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2022-06-28T00:13:28.000Z (over 2 years ago)
- Last Synced: 2024-10-30T16:56:24.405Z (3 months ago)
- Language: Erlang
- Size: 73.2 KB
- Stars: 1
- Watchers: 1
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Le'Json - Lightweight Erlang Json library
Requires R17 since it produces maps on decode. Not yet handling unicode
code points like "\\uD8B3" (arabic) correctly. Other than that it seem
to keep with the standard (rfc4627). Encoding is also compatible with rfc8259.## Exports
```erlang
-type json_key() :: atom() | string() | binary().
-type json_value() :: boolean() | 'null' | calendar:datetime() | atom()
| number() | binary() | json_object() | json_array().
-type json_object() :: #{json_key() => json_value()}.
-type json_array() :: [json_value()].
-type json_opts() :: #{'keys' => 'atom' | 'existing_atom' | 'list'}.-spec lejson:decode(iodata()) -> json_object() | json_array() | {error, not_json}.
-spec lejson:decode(iodata(), json_opts()) ->
json_object() | json_array() | {error, not_json}.-spec lejson:encode(json_value()) -> binary().
```## Example usage
```erlang
1> l(lejson).
ok
2> M = lejson:decode(<<"{\"boolean\": [true, false],
\"neg_num\": -12,
\"floats\": [-22.3, -22.3e-12, 22.3E-12,
22.3E+4, 22.3E+4, 22.3E4],
\"null\": null,
\"pos_int\": 6789,
\"string_value\": \"value\",
\"utf_value\": \"\\uC3B8 and \\uc2a9\",
\"arabic\": \"\\uD8B3\\ud8b5\\ud8b8\",
\"more unicode\": \" \\uD834 \\uDD1E \",
\"array\": [{\"object_inside_array\": 1}],
\"nested_array\": [[[79]]],
\"another_array\": [1,2,3,[1,[2],3],12]}">>).
#{<<"another_array">> => [1,2,3,[1,[2],3],12],
<<"arabic">> => <<216,179,216,181,216,184>>,
<<"array">> => [#{<<"object_inside_array">> => 1}],
<<"boolean">> => [true,false],
<<"floats">> => [-22.3,-2.23e-11,2.23e-11,2.23e5,2.23e5,2.23e5],
<<"more unicode">> => <<32,216,52,32,221,30,32>>,
<<"neg_num">> => -12,
<<"nested_array">> => [["O"]],
<<"null">> => null,
<<"pos_int">> => 6789,
<<"string_value">> => <<"value">>,
<<"utf_value">> => <<"ø and ©"/utf8>>}
3> lejson:encode(M)
<<"{\"another_array\": [1, 2, 3, [1, [2], 3], 12],\"arabic\": \""...>>
```## License
Apache license version 2.0. See the LICENSE file for details.