3636% %% API
3737% % @doc Returns an empty list if the given value is ?not_found.
3838-spec empty_if_not_found (Value :: any ()) -> any ().
39- empty_if_not_found (? not_found ) -> [];
40- empty_if_not_found (Value ) -> Value .
39+ empty_if_not_found (? not_found ) ->
40+ [];
41+ empty_if_not_found (Value ) ->
42+ Value .
4143
4244% % @doc Checks if the given value is json `array'.
4345% % This check is needed since objects in `jsx' are lists (proplists).
4446-spec is_array (Value :: any ()) -> boolean ().
45- is_array (Value ) when is_list (Value ) -> not is_json_object (Value );
46- is_array (_ ) -> false .
47+ is_array (Value )
48+ when is_list (Value ) ->
49+ not is_json_object (Value );
50+ is_array (_ ) ->
51+ false .
4752
4853% % @doc A naive check if the given data is a json object.
4954% % Supports two main formats of json representation:
@@ -52,18 +57,32 @@ is_array(_) -> false.
5257% % 3) jsx format (`[{binary() | atom(), any()}]')
5358% % Returns `true' if the given data is an object, otherwise `false' is returned.
5459-spec is_json_object (Value :: any ()) -> boolean ().
55- is_json_object ({struct , Value }) when is_list (Value ) -> true ;
56- is_json_object ({Value }) when is_list (Value ) -> true ;
60+ is_json_object ({struct , Value })
61+ when is_list (Value ) ->
62+ true ;
63+ is_json_object ({Value })
64+ when is_list (Value ) ->
65+ true ;
5766% % handle `jsx' empty objects
58- is_json_object ([{}]) -> true ;
67+ is_json_object ([{}]) ->
68+ true ;
5969% % very naive check. checks only the first element.
6070is_json_object ([{Key , _Value } | _ ])
6171 when is_binary (Key ) orelse is_atom (Key )
62- andalso Key =/= struct -> true ;
63- ? IF_MAPS (is_json_object (Map ) when erlang :is_map (Map ) -> true ;)
64- is_json_object (_ ) -> false .
72+ andalso Key =/= struct ->
73+ true ;
74+ ? IF_MAPS (
75+ is_json_object (Map )
76+ when erlang :is_map (Map ) ->
77+ true ;
78+ )
79+ is_json_object (_ ) ->
80+ false .
6581
6682% % @doc Checks if the given value is json `null'.
6783-spec is_null (Value :: any ()) -> boolean ().
68- is_null (null ) -> true ;
69- is_null (_Value ) -> false .
84+ is_null (null ) ->
85+ true ;
86+ is_null (_Value ) ->
87+ false .
88+
0 commit comments