From 0ca877f92518929301cc0151f3cf5dfd30aca06c Mon Sep 17 00:00:00 2001 From: Pawel Chmielowski Date: Tue, 7 Oct 2025 14:40:45 +0200 Subject: [PATCH] make misc:json_encode always call json with our filter --- src/misc.erl | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/misc.erl b/src/misc.erl index 87f8b24e6..fb5f6bc05 100644 --- a/src/misc.erl +++ b/src/misc.erl @@ -126,18 +126,16 @@ json_encode(Term) -> json_decode(Bin) -> jiffy:decode(Bin, [return_maps]). -else. -json_encode({[{_Key, _Value} | _]} = Term) -> +json_encode({[]}) -> + %% Jiffy was able to handle this case, but Json library does not + <<"{}">>; +json_encode(Term) -> iolist_to_binary(json:encode(Term, fun({Val}, Encoder) when is_list(Val) -> json:encode_key_value_list(Val, Encoder); (Val, Encoder) -> json:encode_value(Val, Encoder) - end)); -json_encode({[]}) -> - %% Jiffy was able to handle this case, but Json library does not - <<"{}">>; -json_encode(Term) -> - iolist_to_binary(json:encode(Term)). + end)). json_decode(Bin) -> json:decode(Bin). -endif.