Sometimes we want to convert from map to struct or struct to map (dictionary in other language), or even struct to struct. There's some library that can help us doing this, for example structs, mapstructure, copier, or smapping. We could also utilize serialization and deserialization libraries to do this. With caveats, that some serialization format (eg. JSON) doesn't allow integer larger than 2^53 for example.
Here's benchmark that I run this morning:
The repository and the always updated result is here, feel free to add your own serialization/deserialization library. As we can see, goccy-gojson is the fastest among all, too bad if you store int64 larger than 2^53 it give wrong result. So it's better to use second best and all rounder vmihailenco-msgpack, or for specific use case struct to map/struct is mapstructure.
Here's the top ranking:
| Ser/Deser | M2S | S2M | S2S |
|---|---|---|---|
| GoccyGoJson | 1 | 2 | 2 |
| JsonIteratorGo | 2 | 3 | 4 |
| MitchellhMapstructure | 8 | 1 | 1 |
| VmihailencoMspackV5 | 3 | 4 | 7 |
| FxamackerCbor | 4 | 5 | 5 |
| ShamatonMsgpackV2 | 7 | 6 | 3 |
| SurrealdbCork | 5 | 8 | 12 |

