mirror of
https://github.com/json-iterator/go.git
synced 2024-11-27 08:30:57 +02:00
#126 add space between map key and value when MarshalIndent
This commit is contained in:
parent
45c22b130b
commit
d37197e176
@ -102,6 +102,9 @@ func (encoder *mapEncoder) Encode(ptr unsafe.Pointer, stream *Stream) {
|
||||
}
|
||||
encodeMapKey(key, stream)
|
||||
stream.writeByte(':')
|
||||
if stream.indention > 0 {
|
||||
stream.writeByte(' ')
|
||||
}
|
||||
val := realVal.MapIndex(key).Interface()
|
||||
encoder.elemEncoder.EncodeInterface(val, stream)
|
||||
}
|
||||
|
@ -68,3 +68,14 @@ func Test_marshal_indent(t *testing.T) {
|
||||
should.Nil(err)
|
||||
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))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user