The OrderedMap open source repository may meet your needs. It supports JSON Serialization of ordered maps.
Code example:
package main
import (
"encoding/json"
"fmt"
xmap "github.com/danielhookx/xcontainer/map"
)
func main() {
srcJson := `{"name": "John", "age": 30, "city": "New York"}`
var fields xmap.OrderedMap[string, interface{}]
err := json.Unmarshal([]byte(srcJson), &fields)
if err != nil {
fmt.Println(err)
}
for key, value := range fields.Iter() {
fmt.Println(key, value)
}
}
Execution Results:
$ go run main.go
name John
age 30
city New York