79537870

Date: 2025-03-27 05:16:11
Score: 1
Natty:
Report link

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
Reasons:
  • Contains signature (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Daniel