Skip to content

Commit 97f622b

Browse files
committed
cue: marshal a Value as JSON null directly
json.Marshal(nil) always produces ([]byte("null"), nil). Doing so directly is more straightforward to understand and cheaper. Signed-off-by: Daniel Martí <[email protected]> Change-Id: I77452e40374c642400d873a56dda7d7723f8c537 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1201805 Unity-Result: CUE porcuepine <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Roger Peppe <[email protected]>
1 parent 7ba104c commit 97f622b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

cue/types.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ func (v Value) MarshalJSON() (b []byte, err error) {
911911
func (v Value) marshalJSON() (b []byte, err error) {
912912
v, _ = v.Default()
913913
if v.v == nil {
914-
return internaljson.Marshal(nil)
914+
return []byte("null"), nil
915915
}
916916
ctx := newContext(v.idx)
917917
x := v.eval(ctx)
@@ -926,7 +926,7 @@ func (v Value) marshalJSON() (b []byte, err error) {
926926
// TODO: implement marshalles in value.
927927
switch k := x.Kind(); k {
928928
case adt.NullKind:
929-
return internaljson.Marshal(nil)
929+
return []byte("null"), nil
930930
case adt.BoolKind:
931931
return internaljson.Marshal(x.(*adt.Bool).B)
932932
case adt.IntKind, adt.FloatKind, adt.NumberKind:

0 commit comments

Comments
 (0)