Golang:json Unmarshal无法解压缩简单示例

I cannot get my head around this problem. I have a simple struct, and another struct that uses it twice:

type Range struct {
    Position int `json:"position"`
    Length   int `json:"length"`
}

type TwoRanges struct {
    From Range `json:"from"`
    To   Range `json:"to"`
}

and the following json sample in file "ranges.json":

{
"from:": {
    "position": 348,
    "length": 15
},
"to": {
    "position": 737,
    "length" : 10
}
}

I try unmarshalling the sample in the following code:

func main() {
    buffer, err := ioutil.ReadFile("ranges.json")
    if err != nil {
        log.Fatal(err)
    }
    var sample TwoRanges
    if err = json.Unmarshal(buffer, &sample); err != nil {
        log.Fatal(err)
    }

    fmt.Printf("%v
", sample)
}

The output is

{{0 0} {737 10}}

Somehow, only the half of the struct is unpacked.

  1. Is it a bug, or am I doing something wrong?
  2. Is there a "verbose mode" for the encoding/json package which would tell me what went wrong with the unmarshaller? It's not the first time that I've had mysterious problems with that package.

note that:

the "from:" should be "from" in your ranges.json

The json has bad formatted, look the colon afer from : { "from:": { .....