The stream borrowed from sync.Pool always has 0 initial indention and returned with 0 indention. So when processing nested elements if SortMapKeys: true is configured inside the Config, the encoding will always have a single unit of indention step. eg.
var json = jsoniter.ConfigCompatibleWithStandardLibrary
var obj interface{}
var x []byte
There are some cases
jsoniter
behaves incorrectly when marshaling map/object with indention.sortedKeysMapEncoder
have incorrect indentions.The
stream
borrowed fromsync.Pool
always has 0 initial indention and returned with 0 indention. So when processing nested elements ifSortMapKeys: true
is configured inside theConfig
, the encoding will always have a single unit of indention step. eg.obj = map[int]map[int]int{1: {1: 2}} x, _ = json.MarshalIndent(obj, "", " ") fmt.Println(string(x))
obj = map[int]map[int]int{1: {1: 2}} x, _ = json.MarshalIndent(obj, "", " ") fmt.Println(string(x))
obj = map[int]struct{ F int }{1: {F: 2}} x, _ = json.MarshalIndent(obj, "", " ") fmt.Println(string(x))
Expects:
(*Stream).WriteObjectStart
.omitempty
tag will have redundant indention if these exported fields are all empty.obj = map[int]int{} x, _ = json.MarshalIndent(obj, "", " ") fmt.Println(string(x))
obj = struct { Empty int
json:"empty,omitempty"
}{} x, _ = json.MarshalIndent(obj, "", " ") fmt.Println(string(x))Expects: