Merge branch 'develop'

This commit is contained in:
alisdair sullivan 2016-12-08 10:08:19 -08:00
commit f96d9e0b9d
5 changed files with 39 additions and 8 deletions

View file

@ -48,6 +48,18 @@ for the overview or [migrating from 1.x](#migrating) for the details
## quickstart ## ## 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 #### #### to build the library and run tests ####
```bash ```bash

View file

@ -7,7 +7,7 @@ use Mix.Project
version: "2.8.0", version: "2.8.0",
description: "an erlang application for consuming, producing and manipulating json. inspired by yajl", description: "an erlang application for consuming, producing and manipulating json. inspired by yajl",
deps: deps(Mix.env), deps: deps(Mix.env),
package: package, package: package(),
language: :erlang, language: :erlang,
erlc_options: opts(Mix.env) erlc_options: opts(Mix.env)
] ]
@ -19,8 +19,8 @@ use Mix.Project
nil -> [] nil -> []
_ -> [d: :maps_always] _ -> [d: :maps_always]
end end
[d: :maps_support] ++ force_maps [:debug_info, d: :maps_support] ++ force_maps
end end
defp deps(_), do: [{:mixunit, "~> 0.9.2", only: :dev}] defp deps(_), do: [{:mixunit, "~> 0.9.2", only: :dev}]
@ -41,4 +41,3 @@ use Mix.Project
] ]
end end
end end

View file

@ -44,7 +44,7 @@
-ifndef(maps_support). -ifndef(maps_support).
-type json_term() :: [{binary() | atom(), json_term()}] | [{}] -type json_term() :: [{binary() | atom(), json_term()}] | [{},...]
| [json_term()] | [] | [json_term()] | []
| true | false | null | true | false | null
| integer() | float() | integer() | float()
@ -53,7 +53,7 @@
-endif. -endif.
-ifdef(maps_support). -ifdef(maps_support).
-type json_term() :: [{binary() | atom(), json_term()}] | [{}] -type json_term() :: [{binary() | atom(), json_term()}] | [{},...]
| [json_term()] | [] | [json_term()] | []
| map() | map()
| true | false | null | true | false | null

View file

@ -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); maybe_done(Tokens, handle_event({float, Number}, Handler, Config), Stack, Config);
value([{raw, Raw}|Tokens], Handler, Stack, Config) when is_binary(Raw) -> value([{raw, Raw}|Tokens], Handler, Stack, Config) when is_binary(Raw) ->
value((jsx:decoder(?MODULE, [], []))(Raw) ++ Tokens, Handler, Stack, Config); 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) 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) -> 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( 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_() -> rogue_tuple_test_() ->
[ [
{"kv in value position of object", ?_assertError( {"kv in value position of object", ?_assertError(

View file

@ -46,7 +46,7 @@
-ifndef(maps_support). -ifndef(maps_support).
-type json_value() :: list(json_value()) -type json_value() :: list(json_value())
| list({binary() | atom(), json_value()}) | list({binary() | atom(), json_value()}) | [{},...]
| true | true
| false | false
| null | null
@ -57,7 +57,7 @@
-ifdef(maps_support). -ifdef(maps_support).
-type json_value() :: list(json_value()) -type json_value() :: list(json_value())
| list({binary() | atom(), json_value()}) | list({binary() | atom(), json_value()}) | [{},...]
| map() | map()
| true | true
| false | false