From f511aeba70cd5b8cb4734395870a575c1dfdb6f6 Mon Sep 17 00:00:00 2001 From: alisdair sullivan Date: Sun, 20 May 2012 16:59:11 -0700 Subject: [PATCH] expanded examples in quickstart --- README.markdown | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/README.markdown b/README.markdown index 4841286..091d93d 100644 --- a/README.markdown +++ b/README.markdown @@ -58,24 +58,57 @@ to convert a utf8 binary containing a json string into an erlang term ```erlang 1> jsx:to_term(<<"{\"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 ```erlang -1> jsx:to_json([<<"a">>, <<"list">>, <<"of">>, <<"words">>]). -<<"[\"a\",\"list\",\"of\",\"words\"]">> +1> jsx:to_json([{<<"library">>,<<"jsx">>},{<<"awesome">>,true}]). +<<"{\"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 ```erlang -1> jsx:is_json(<<"[1]">>). +1> jsx:is_json(<<"[\"this is json\"]">>). true -2> jsx:is_term(1). +2> jsx:is_json("[\"this is not\"]"). +false +3> jsx:is_term([<<"this is a term">>]). 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 + ] +}">> +``` ## api ##