diff --git a/array.go b/array.go index aa4f623..d88c497 100644 --- a/array.go +++ b/array.go @@ -85,6 +85,12 @@ func (a *Array) Hex(val []byte) *Array { return a } +// RawJSON adds already encoded JSON to the array. +func (a *Array) RawJSON(val []byte) *Array { + a.buf = appendJSON(enc.AppendArrayDelim(a.buf), val) + return a +} + // Err serializes and appends the err to the array. func (a *Array) Err(err error) *Array { marshaled := ErrorMarshalFunc(err) diff --git a/array_test.go b/array_test.go index 66c6668..e8857e6 100644 --- a/array_test.go +++ b/array_test.go @@ -24,10 +24,11 @@ func TestArray(t *testing.T) { Str("a"). Bytes([]byte("b")). Hex([]byte{0x1f}). + RawJSON([]byte(`{"some":"json"}`)). Time(time.Time{}). IPAddr(net.IP{192, 168, 0, 10}). Dur(0) - want := `[true,1,2,3,4,5,6,7,8,9,10,11.98122,12.987654321,"a","b","1f","0001-01-01T00:00:00Z","192.168.0.10",0]` + want := `[true,1,2,3,4,5,6,7,8,9,10,11.98122,12.987654321,"a","b","1f",{"some":"json"},"0001-01-01T00:00:00Z","192.168.0.10",0]` if got := decodeObjectToStr(a.write([]byte{})); got != want { t.Errorf("Array.write()\ngot: %s\nwant: %s", got, want) }