json-iterator / go

A high-performance 100% compatible drop-in replacement of "encoding/json"
http://jsoniter.com/migrate-from-go-std.html
MIT License
13.42k stars 1.03k forks source link

Incorrect formatting of nested JSON indentation #604

Open 93Alliance opened 2 years ago

93Alliance commented 2 years ago

right usage

m := make(map[string]interface{})
m["json.maxItemsComputed"] = 8000
m["C_Cpp.formatting"] = "Disabled"
m["workbench.iconTheme"] = "vscode-icons-mac"
m["C_Cpp.autocomplete"] = "Disabled"
m["editor.folding"] = map[string]interface{}{
"ssss": 123,
}
s, _ := jsoniter.MarshalIndent(m, "", "    ")
fmt.Println(string(s))

image

wrong usage

m := make(map[string]interface{})
m["json.maxItemsComputed"] = 8000
m["C_Cpp.formatting"] = "Disabled"
m["workbench.iconTheme"] = "vscode-icons-mac"
m["C_Cpp.autocomplete"] = "Disabled"
m["editor.folding"] = map[string]interface{}{
"ssss": 123,
}
cfg := jsoniter.Config{
SortMapKeys: true,
EscapeHTML:  false,
}.Froze()
s, _ := cfg.MarshalIndent(m, "", "    ")
fmt.Println(string(s))

image

micln commented 2 years ago

same problem: https://go.dev/play/p/nCOu2IroD0E

93Alliance commented 2 years ago

I want to use sort, how can i solve it?

creekwax commented 2 years ago

Seems not active for too long. The same issue #564 has been open for half a year 😞

dashaaa commented 2 years ago

Hitting the same issue.