diff --git a/zio/zjsonio/writer.go b/zio/zjsonio/writer.go index 9ebb952102..19efcf1820 100644 --- a/zio/zjsonio/writer.go +++ b/zio/zjsonio/writer.go @@ -163,9 +163,10 @@ func (w *Writer) encodeMap(zctx *zed.Context, typ *zed.TypeMap, v zcode.Bytes) ( if v == nil { return nil, nil } - var out []interface{} - it := v.Iter() - for !it.Done() { + // We start out with a slice that contains nothing instead of nil + // so that an empty map encodes as a JSON empty array []. + out := []interface{}{} + for it := v.Iter(); !it.Done(); { pair := make([]interface{}, 2) var err error pair[0], err = w.encodeValue(zctx, typ.KeyType, it.Next()) diff --git a/zio/zjsonio/ztests/vals.yaml b/zio/zjsonio/ztests/vals.yaml index 01020f623d..9292bf70b9 100644 --- a/zio/zjsonio/ztests/vals.yaml +++ b/zio/zjsonio/ztests/vals.yaml @@ -9,6 +9,7 @@ inputs: "hello" [3,4] {a:1} + |{}| true false 1((int64,string))