var v []int
fmt.Println(json.Unmarshal([]byte(`["foo"]`), &v))

v1 error: "json: cannot unmarshal string into Go value of type int" v1-wrapping-v2 error: "json: cannot unmarshal string into Go struct field .0 of type int"

But there's no struct involved.

The plain v2 error is better, probably fine: json: cannot unmarshal JSON string into Go int within "/0"

Comment From: neild

/cc @dsnet

Comment From: gabyhelp

Related Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

Comment From: dsnet

I don't know how to easily fix this.

The JSON Pointer (RFC 6901) lacks type information about whether a token corresponds with a JSON array or a JSON object. Even if we could detect that, we still don't know if a JSON object name corresponds with a Go map key or a Go struct field.

I'm more inclined to fix the error message to stop saying "into Go struct field", but that would be a more invasive change. The previous wording has always been somewhat of a lie since the error construction used an odd mix of both the JSON namespace and the Go namespace.