summaryrefslogtreecommitdiff
path: root/libgo/go/json/encode.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/json/encode.go')
-rw-r--r--libgo/go/json/encode.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/libgo/go/json/encode.go b/libgo/go/json/encode.go
index 46abe4360ed..ba5c15cc496 100644
--- a/libgo/go/json/encode.go
+++ b/libgo/go/json/encode.go
@@ -352,7 +352,15 @@ func (e *encodeState) reflectValueQuoted(v reflect.Value, quoted bool) {
}
e.WriteByte('}')
- case reflect.Array, reflect.Slice:
+ case reflect.Slice:
+ if v.IsNil() {
+ e.WriteString("null")
+ break
+ }
+ // Slices can be marshalled as nil, but otherwise are handled
+ // as arrays.
+ fallthrough
+ case reflect.Array:
if v.Type() == byteSliceType {
e.WriteByte('"')
s := v.Interface().([]byte)