# Module jsone #
* [Description](#description)
* [Data Types](#types)
* [Function Index](#index)
* [Function Details](#functions)
JSON decoding/encoding module.
## Data Types ##
### json_array() ###
json_array() = [json_value()]
### json_boolean() ###
json_boolean() = boolean()
### json_number() ###
json_number() = number()
### json_object() ###
json_object() = {json_object_members()}
### json_object_members() ###
json_object_members() = [{json_string(), json_value()}]
### json_string() ###
json_string() = binary()
### json_value() ###
json_value() = json_number() | json_string() | json_array() | json_object() | json_boolean() | null
## Function Index ##
decode/1 | Decodes an erlang term from json text (a utf8 encoded binary). |
encode/1 | Encodes an erlang term into json text (a utf8 encoded binary). |
try_decode/1 | Decodes an erlang term from json text (a utf8 encoded binary). |
try_encode/1 | Encodes an erlang term into json text (a utf8 encoded binary). |
## Function Details ##
### decode/1 ###
decode(Json::binary()) -> json_value()
Decodes an erlang term from json text (a utf8 encoded binary)
Raises an error exception if input is not valid json
```
> jsone:decode(<<"1">>).
1
> jsone:decode(<<"wrong json">>).
** exception error: bad argument
in function jsone_decode:number_integer_part/4
called as jsone_decode:number_integer_part(<<"wrong json">>,1,[],<<>>)
in call from jsone:decode/1 (src/jsone.erl, line 71)
```
### encode/1 ###
encode(JsonValue::json_value()) -> binary()
Encodes an erlang term into json text (a utf8 encoded binary)
Raises an error exception if input is not an instance of type `json_value()`
```
> jsone:encode([1, null, 2]).
<<"[1,null,2]">>
> jsone:encode([1, hoge, 2]). % 'hoge' atom is not a json value
** exception error: bad argument
in function jsone_encode:value/3
called as jsone_encode:value(hoge,[{array_values,[2]}],<<"[1,">>)
in call from jsone:encode/1 (src/jsone.erl, line 97)
```
### try_decode/1 ###
try_decode(Json::binary()) -> {ok, json_value(), Remainings::binary()} | {error, {Reason::term(), [erlang:stack_item()]}}
Decodes an erlang term from json text (a utf8 encoded binary)
```
> jsone:try_decode(<<"[1,2,3] \"next value\"">>).
{ok,[1,2,3],<<" \"next value\"">>}
> jsone:try_decode(<<"wrong json">>).
{error,{badarg,[{jsone_decode,number_integer_part,
[<<"wrong json">>,1,[],<<>>],
[{line,208}]}]}}
```
### try_encode/1 ###
try_encode(JsonValue::json_value()) -> {ok, binary()} | {error, {Reason::term(), [erlang:stack_item()]}}
Encodes an erlang term into json text (a utf8 encoded binary)
```
> jsone:try_encode([1, null, 2]).
{ok,<<"[1,null,2]">>}
> jsone:try_encode([1, hoge, 2]). % 'hoge' atom is not a json value
{error,{badarg,[{jsone_encode,value,
[hoge,[{array_values,[2]}],<<"[1,">>],
[{line,86}]}]}}
```