diff --git a/lib/json.go b/lib/json.go index f23484c..fa08b32 100644 --- a/lib/json.go +++ b/lib/json.go @@ -251,7 +251,7 @@ func encodeJSON(val ref.Val) ref.Val { switch under := val.Value().(type) { case map[string]any: v = under - case map[ref.Val]ref.Val: + case map[ref.Val]ref.Val, []ref.Val: pb, err := val.ConvertToNative(structpbValueType) if err != nil { return types.NewErr("failed proto conversion: %v", err) diff --git a/testdata/json_encode.txt b/testdata/json_encode.txt index 0fea196..0f22481 100644 --- a/testdata/json_encode.txt +++ b/testdata/json_encode.txt @@ -23,6 +23,7 @@ cmp stdout want.txt }), "plain text".encode_json(), encode_json("plain text"), + [0, 1].map(i, {"a":i}).encode_json() ] -- want.txt -- [ @@ -32,5 +33,6 @@ cmp stdout want.txt "{\"a\":{\"b\":{\"c\":1}}}", "{\"a\":{\"b\":{\"c\":1}}}", "\"plain text\"", - "\"plain text\"" + "\"plain text\"", + "[{\"a\":0},{\"a\":1}]" ]