Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encoding/json: add offset to the reported errors #9693

xarg opened this issue Jan 26, 2015 · 0 comments

encoding/json: add offset to the reported errors #9693

xarg opened this issue Jan 26, 2015 · 0 comments


Copy link

xarg commented Jan 26, 2015

Sometimes JSON data can be inconsistent (Ex: bad APIs). One field can be string in one row, in another float64. It would help to figure out what field is responsible if there was at least the offset from the JSON file associated with the reported error.


type NEObject struct {
    A1            string  `json:"A1"`
    A2            string  `json:"A2"`
    A3            string  `json:"A3"`
    BV            float64 `json:"BV"`
    DT            string  `json:"DT"`
    G             float64 `json:"G"`
    GM            float64 `json:"GM"`
    H             float64 `json:"H"`
    HSigma        string  `json:"H_sigma"`

Suppose there is a data.json file that contains 10k rows and row 1230 has field HSigma a float64 instead of string. The error reported when unmarshalling would be:

json: cannot unmarshal string into Go value of type float64

Which is not very useful since we have a few string fields and we don't know the row. Instead something like this would tell me where I should look in my json file:

json: cannot unmarshal 'string' into Go value of type 'float64' offset 7427

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet

No branches or pull requests

2 participants