gojson icon indicating copy to clipboard operation
gojson copied to clipboard

Parse decimals ending in .0 as floats instead of ints

Open ChimeraCoder opened this issue 8 years ago • 0 comments

{
    "value": 10.0,
    "timestamp": 147847894,
}

value should be parsed as a float64, but timestamp should be an int64.

This comes from @nstogner: (https://github.com/ChimeraCoder/gojson/pull/22#issuecomment-248996855)

To elaborate on my personal use-case: I would like to be able to define a struct's default values via a JSON object... To do this I would like to use gojson to first create the struct and then use another process to read in the object again to determine the default values, ie:

{ "name": "", "health": "100", "score": 0.0 } -- piped thru gojson -->

type Foo struct {
Name string `json:"name"`
Health int `json:"health"` 
Score float64 `json:"score"` 
}

-- JSON object piped thru extra process -->

f := Foo{
Health: 100,
}

In other words, I would need to be able to support 0.0 values which get translated into floats.

ChimeraCoder avatar Nov 07 '16 00:11 ChimeraCoder