Skip to content

Commit

Permalink
Fix empty Zed map encoding in zio/zjsonio.Writer (#4853)
Browse files Browse the repository at this point in the history
Closes #4851.
  • Loading branch information
nwt authored Nov 4, 2023
1 parent 07986f7 commit 7dc91f9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
7 changes: 4 additions & 3 deletions zio/zjsonio/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
1 change: 1 addition & 0 deletions zio/zjsonio/ztests/vals.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ inputs:
"hello"
[3,4]
{a:1}
|{}|
true
false
1((int64,string))
Expand Down

0 comments on commit 7dc91f9

Please sign in to comment.