diff --git a/src/jsn.erl b/src/jsn.erl index 393a1c3..2927dfe 100644 --- a/src/jsn.erl +++ b/src/jsn.erl @@ -989,7 +989,8 @@ keys_set(Keys, {P}, Value, Empty) when is_list(P) -> keys_set([Key | Rest], Object, Value, Empty) when is_binary(Key), (is_list(Object) orelse is_map(Object)) -> case key_get(Key, Object, jsn__undefined) of - E when Value =:= jsn__delete, (E =:= jsn__undefined orelse E =:= Empty) -> + E when Value =:= jsn__delete, Rest /= [], + (E =:= jsn__undefined orelse E =:= Empty) -> return_if_object(Object, Empty); E when E =:= jsn__undefined; E =:= Empty -> key_set(Key, Object, keys_set(Rest, Empty, Value, Empty)); diff --git a/test/jsn_tests.erl b/test/jsn_tests.erl index 6797a9b..a707b26 100644 --- a/test/jsn_tests.erl +++ b/test/jsn_tests.erl @@ -295,6 +295,12 @@ delete_test_() -> ?_assertEqual(#{}, jsn:delete(Path3, #{})), ?_assertEqual([], jsn:delete(<<"foo">>, [{<<"foo">>, <<"bar">>}])), ?_assertEqual(#{}, jsn:delete(<<"foo">>, #{<<"foo">> => <<"bar">>})), + ?_assertEqual(#{}, jsn:delete(<<"foo">>, #{<<"foo">> => #{}})), + ?_assertEqual(#{}, jsn:delete(<<"foo">>, #{<<"foo">> => []})), + ?_assertEqual(#{<<"foo">> => #{}}, + jsn:delete(<<"foo.bar">>, #{<<"foo">> => #{<<"bar">> => #{}}})), + ?_assertEqual(#{<<"foo">> => #{<<"bar">> => #{}}}, + jsn:delete(<<"foo.baz">>, #{<<"foo">> => #{<<"bar">> => #{}}})), ?_assertEqual(jsn:new({Path2, [1,2,3]}, [{format, proplist}]), jsn:delete(foo, Object1Plist)), ?_assertEqual(jsn:new({Path2, [1,2,3]}, [{format, map}]),