Skip to content

Instantly share code, notes, and snippets.

@abstractart
Created November 10, 2021 09:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abstractart/adac1ab4dbcccf243760379e08dccb65 to your computer and use it in GitHub Desktop.
Save abstractart/adac1ab4dbcccf243760379e08dccb65 to your computer and use it in GitHub Desktop.
BigIntegers Serialization and Deserialization in Golang
package main
import (
"bytes"
"encoding/json"
"fmt"
)
func main() {
jsonStr := "{\"time\":9223372036854775807}\n"
var jsonMap map[string]interface{}
d := json.NewDecoder(bytes.NewBuffer([]byte(jsonStr)))
d.UseNumber()
d.Decode(&jsonMap)
var bytes bytes.Buffer
e := json.NewEncoder(&bytes)
e.Encode(jsonMap)
fmt.Print(jsonStr)
fmt.Print(bytes.String())
fmt.Print(bytes.String() == jsonStr)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment