expanded examples in quickstart

This commit is contained in:
alisdair sullivan 2012-05-20 16:59:11 -07:00
parent d0fad06d1f
commit f511aeba70

View file

@ -58,24 +58,57 @@ to convert a utf8 binary containing a json string into an erlang term
```erlang ```erlang
1> jsx:to_term(<<"{\"library\": \"jsx\", \"awesome\": true}">>). 1> jsx:to_term(<<"{\"library\": \"jsx\", \"awesome\": true}">>).
[{<<"library">>,<<"jsx">>},{<<"awesome">>,true}] [{<<"library">>,<<"jsx">>},{<<"awesome">>,true}]
2> jsx:to_term(<<"[\"a\",\"list\",\"of\",\"words\"]">>).
[<<"a">>, <<"list">>, <<"of">>, <<"words">>]
``` ```
to convert an erlang term into a utf8 binary containing a json string to convert an erlang term into a utf8 binary containing a json string
```erlang ```erlang
1> jsx:to_json([<<"a">>, <<"list">>, <<"of">>, <<"words">>]). 1> jsx:to_json([{<<"library">>,<<"jsx">>},{<<"awesome">>,true}]).
<<"[\"a\",\"list\",\"of\",\"words\"]">> <<"{\"library\": \"jsx\", \"awesome\": true}">>
2> jsx:to_json([<<"a">>, <<"list">>, <<"of">>, <<"words">>]).
<<"[\"a\",\"list\",\"of\",\"words\"]">>
``` ```
to check if a binary or a term is valid json to check if a binary or a term is valid json
```erlang ```erlang
1> jsx:is_json(<<"[1]">>). 1> jsx:is_json(<<"[\"this is json\"]">>).
true true
2> jsx:is_term(1). 2> jsx:is_json("[\"this is not\"]").
false
3> jsx:is_term([<<"this is a term">>]).
true true
4> jsx:is_term(["this is not"]).
false
``` ```
to minify some json
```erlang
1> jsx:minify(<<"{
\"a list\": [
1,
2,
3
]
}">>).
<<"{\"a list\":[1,2,3]}">>
```
to prettify some json
```erlang
1> jsx:prettify(<<"{\"a list\":[1,2,3]}">>).
<<"{
\"a list\": [
1,
2,
3
]
}">>
```
## <a name="api">api</a> ## ## <a name="api">api</a> ##