Merge branch 'develop'
This commit is contained in:
commit
f96d9e0b9d
5 changed files with 39 additions and 8 deletions
12
README.md
12
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
|
||||
|
|
5
mix.exs
5
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,7 +19,7 @@ use Mix.Project
|
|||
nil -> []
|
||||
_ -> [d: :maps_always]
|
||||
end
|
||||
[d: :maps_support] ++ force_maps
|
||||
[: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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue