Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Solution 1</strong> </p> <p>You can use a <a href="http://golang.org/pkg/encoding/json/#Decoder" rel="noreferrer">Decoder</a> and <a href="http://golang.org/pkg/encoding/json/#Decoder.UseNumber" rel="noreferrer">UseNumber</a> to decode your numbers without loss :</p> <p>The <code>Number</code> type is defined like this :</p> <pre><code>// A Number represents a JSON number literal. type Number string </code></pre> <p>which means you can easily convert it :</p> <pre><code>package main import ( "encoding/json" "fmt" "bytes" "strconv" ) func main() { body := []byte("{\"tags\":[{\"id\":4418489049307132905},{\"id\":4418489049307132906}]}") dat := make(map[string]interface{}) d := json.NewDecoder(bytes.NewBuffer(body)) d.UseNumber() if err := d.Decode(&amp;dat); err != nil { panic(err) } tags := dat["tags"].([]interface{}) n := tags[0].(map[string]interface{})["id"].(json.Number) i64, _ := strconv.ParseUint(string(n), 10, 64) fmt.Println(i64) // prints 4418489049307132905 } </code></pre> <p><strong>Solution 2</strong></p> <p>You can also decode into a specific structure tailored to your needs :</p> <pre><code>package main import ( "encoding/json" "fmt" ) type A struct { Tags []map[string]uint64 // "tags" } func main() { body := []byte("{\"tags\":[{\"id\":4418489049307132905},{\"id\":4418489049307132906}]}") var a A if err := json.Unmarshal(body, &amp;a); err != nil { panic(err) } fmt.Println(a.Tags[0]["id"]) // logs 4418489049307132905 } </code></pre> <p>Personally I generally prefer this solution which feels more structured and easier to maintain. </p> <p><strong>Caution</strong></p> <p>A small note if you use JSON because your application is partly in JavaScript : JavaScript has no 64 bits integers but only one number type, which is the IEEE754 double precision float. So you wouldn't be able to parse this JSON in JavaScript without loss using the standard parsing function.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload