|
|
@@ -30,15 +30,8 @@ nested_get(Key, Data) ->
|
|
|
|
|
|
nested_get({var, Key}, Data, Default) ->
|
|
|
general_map_get({key, Key}, Data, Data, Default);
|
|
|
-nested_get({path, Path}, Data, Default) when is_map(Data) orelse is_list(Data),
|
|
|
- is_list(Path) ->
|
|
|
- do_nested_get(Path, Data, Data, Default);
|
|
|
-nested_get(Key, Data, Default) when not is_map(Data) ->
|
|
|
- try emqx_json:decode(Data, [return_maps]) of
|
|
|
- Json -> nested_get(Key, Json, Default)
|
|
|
- catch
|
|
|
- _:_ -> Default
|
|
|
- end.
|
|
|
+nested_get({path, Path}, Data, Default) when is_list(Path) ->
|
|
|
+ do_nested_get(Path, Data, Data, Default).
|
|
|
|
|
|
do_nested_get([Key|More], Data, OrgData, Default) ->
|
|
|
case general_map_get(Key, Data, OrgData, undefined) of
|
|
|
@@ -81,6 +74,12 @@ general_map_put(Key, Val, Map, OrgData) ->
|
|
|
(_) -> do_put(Key, Val, Map, OrgData)
|
|
|
end).
|
|
|
|
|
|
+general_find(KeyOrIndex, Data, OrgData, Handler) when is_binary(Data) ->
|
|
|
+ try emqx_json:decode(Data, [return_maps]) of
|
|
|
+ Json -> general_find(KeyOrIndex, Json, OrgData, Handler)
|
|
|
+ catch
|
|
|
+ _:_ -> Handler(not_found)
|
|
|
+ end;
|
|
|
general_find({key, Key}, Map, _OrgData, Handler) when is_map(Map) ->
|
|
|
case maps:find(Key, Map) of
|
|
|
{ok, Val} -> Handler({found, {{key, Key}, Val}});
|