iancoleman / orderedmap

orderedmap is a golang map where the keys keep the order that they're added. It can be de/serialized from/to JSON. It's based closely on the python collections.OrderedDict.
MIT License
360 stars 55 forks source link

Add option to unmarshal JSON with UseNumber #16

Open stetra opened 3 years ago

stetra commented 3 years ago

This PR adds SetUseNumber which enables the use of UseNumber to prevent precision loss when unmarshalling integers.

Example usage:

func main() {
    o := orderedmap.New()
    o.SetUseNumber(true)
    json.Unmarshal([]byte(`{"x":9007199254740993}`), &o)
    x, _ := o.Get("x")
    fmt.Println(x)

    // Output: 9007199254740993
    // If UseNumber is not called, x will be 9007199254740992.000000
}