diff --git a/README.md b/README.md index a20b7c2..64c39c3 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,18 @@ for the overview or [migrating from 1.x](#migrating) for the details ## quickstart ## +#### to add to a rebar3 project #### +Add to `rebar.config` +```erlang +... +{erl_opts, [debug_info]}. +{deps, [ + ... + {jsx, {git, "https://github.com/talentdeficit/jsx.git", {branch, "v2.8.0"}}} +]}. +... +``` + #### to build the library and run tests #### ```bash diff --git a/mix.exs b/mix.exs index 17272aa..4fbe563 100644 --- a/mix.exs +++ b/mix.exs @@ -7,7 +7,7 @@ use Mix.Project version: "2.8.0", description: "an erlang application for consuming, producing and manipulating json. inspired by yajl", deps: deps(Mix.env), - package: package, + package: package(), language: :erlang, erlc_options: opts(Mix.env) ] @@ -19,8 +19,8 @@ use Mix.Project nil -> [] _ -> [d: :maps_always] end - [d: :maps_support] ++ force_maps - end + [:debug_info, d: :maps_support] ++ force_maps + end defp deps(_), do: [{:mixunit, "~> 0.9.2", only: :dev}] @@ -41,4 +41,3 @@ use Mix.Project ] end end - diff --git a/src/jsx.erl b/src/jsx.erl index 0b55b2e..acdf420 100644 --- a/src/jsx.erl +++ b/src/jsx.erl @@ -44,7 +44,7 @@ -ifndef(maps_support). --type json_term() :: [{binary() | atom(), json_term()}] | [{}] +-type json_term() :: [{binary() | atom(), json_term()}] | [{},...] | [json_term()] | [] | true | false | null | integer() | float() @@ -53,7 +53,7 @@ -endif. -ifdef(maps_support). --type json_term() :: [{binary() | atom(), json_term()}] | [{}] +-type json_term() :: [{binary() | atom(), json_term()}] | [{},...] | [json_term()] | [] | map() | true | false | null diff --git a/src/jsx_parser.erl b/src/jsx_parser.erl index 5dc8653..ca341c0 100644 --- a/src/jsx_parser.erl +++ b/src/jsx_parser.erl @@ -109,6 +109,17 @@ value([Number|Tokens], Handler, Stack, Config) when is_float(Number) -> maybe_done(Tokens, handle_event({float, Number}, Handler, Config), Stack, Config); value([{raw, Raw}|Tokens], Handler, Stack, Config) when is_binary(Raw) -> value((jsx:decoder(?MODULE, [], []))(Raw) ++ Tokens, Handler, Stack, Config); +value([{_,_,_}=Timestamp|Tokens], Handler, Stack, Config) -> + {{Year, Month, Day}, {Hour, Min, Sec}} = calendar:now_to_datetime( + Timestamp), + value([{string, unicode:characters_to_binary(io_lib:format( + "~4.10.0B-~2.10.0B-~2.10.0BT~2.10.0B:~2.10.0B:~2.10.0BZ", + [Year, Month, Day, Hour, Min, Sec] + ))}|Tokens], + Handler, + Stack, + Config + ); value([{{Year, Month, Day}, {Hour, Min, Sec}}|Tokens], Handler, Stack, Config) when is_integer(Year), is_integer(Month), is_integer(Day), is_integer(Hour), is_integer(Min), is_integer(Sec) -> value([{string, unicode:characters_to_binary(io_lib:format( @@ -1178,6 +1189,15 @@ datetime_test_() -> ]. +timestamp_test_() -> + [ + {"timestamp", ?_assertEqual( + [start_array, {string, <<"2016-01-15T18:19:28Z">>}, end_array, end_json], + parse([start_array, {1452,881968,111772}, end_array, end_json], []) + )} + ]. + + rogue_tuple_test_() -> [ {"kv in value position of object", ?_assertError( diff --git a/src/jsx_to_term.erl b/src/jsx_to_term.erl index ec9ab89..aa05264 100644 --- a/src/jsx_to_term.erl +++ b/src/jsx_to_term.erl @@ -46,7 +46,7 @@ -ifndef(maps_support). -type json_value() :: list(json_value()) - | list({binary() | atom(), json_value()}) + | list({binary() | atom(), json_value()}) | [{},...] | true | false | null @@ -57,7 +57,7 @@ -ifdef(maps_support). -type json_value() :: list(json_value()) - | list({binary() | atom(), json_value()}) + | list({binary() | atom(), json_value()}) | [{},...] | map() | true | false