You've already forked json-iterator
mirror of
https://github.com/json-iterator/go.git
synced 2025-06-15 22:50:24 +02:00
#126 add space between map key and value when MarshalIndent
This commit is contained in:
@ -102,6 +102,9 @@ func (encoder *mapEncoder) Encode(ptr unsafe.Pointer, stream *Stream) {
|
|||||||
}
|
}
|
||||||
encodeMapKey(key, stream)
|
encodeMapKey(key, stream)
|
||||||
stream.writeByte(':')
|
stream.writeByte(':')
|
||||||
|
if stream.indention > 0 {
|
||||||
|
stream.writeByte(' ')
|
||||||
|
}
|
||||||
val := realVal.MapIndex(key).Interface()
|
val := realVal.MapIndex(key).Interface()
|
||||||
encoder.elemEncoder.EncodeInterface(val, stream)
|
encoder.elemEncoder.EncodeInterface(val, stream)
|
||||||
}
|
}
|
||||||
|
@ -68,3 +68,14 @@ func Test_marshal_indent(t *testing.T) {
|
|||||||
should.Nil(err)
|
should.Nil(err)
|
||||||
should.Equal("{\n \"F1\": 1,\n \"F2\": [\n 2,\n 3,\n 4\n ]\n}", string(output))
|
should.Equal("{\n \"F1\": 1,\n \"F2\": [\n 2,\n 3,\n 4\n ]\n}", string(output))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_marshal_indent_map(t *testing.T) {
|
||||||
|
should := require.New(t)
|
||||||
|
obj := map[int]int{1: 2}
|
||||||
|
output, err := json.MarshalIndent(obj, "", " ")
|
||||||
|
should.Nil(err)
|
||||||
|
should.Equal("{\n \"1\": 2\n}", string(output))
|
||||||
|
output, err = MarshalIndent(obj, "", " ")
|
||||||
|
should.Nil(err)
|
||||||
|
should.Equal("{\n \"1\": 2\n}", string(output))
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user