diff --git a/tools/write_buffer.go b/tools/write_buffer.go index e67d219..8ae9386 100644 --- a/tools/write_buffer.go +++ b/tools/write_buffer.go @@ -14,6 +14,18 @@ func WriteValue(buff *bytes.Buffer, val any) (n int, err error) { err = fmt.Errorf("Unsupported type %T", v) case nil: return + case []any: + var o []byte + o, err = json.Marshal(v) + if err == nil { + return buff.Write(o) + } + case map[string]any: + var o []byte + o, err = json.Marshal(v) + if err == nil { + return buff.Write(o) + } case string: return buff.WriteString(v) case int: diff --git a/tools/write_buffer_test.go b/tools/write_buffer_test.go index 1a4a103..aa7e203 100644 --- a/tools/write_buffer_test.go +++ b/tools/write_buffer_test.go @@ -30,6 +30,8 @@ func TestWriteBuffer(t *testing.T) { {"json.Number", json.Number("42.13"), "42.13", nil}, {"json.RawMessage", json.RawMessage("{}"), "{}", nil}, {"time", when, when.Format(time.RFC3339), nil}, + {"slice", []any{1, 2, "foo"}, `[1,2,"foo"]`, nil}, + {"map", map[string]any{"baz": 42, "foo": "bar"}, `{"baz":42,"foo":"bar"}`, nil}, {"struct", struct{}{}, "", errors.New("Unsupported type struct {}")}, }