valyala / fastjson

Fast JSON parser and validator for Go. No custom structs, no code generation, no reflection
MIT License
2.3k stars 138 forks source link

clean way to distinguish between float and int numbers? #95

Open Av1shay opened 1 year ago

Av1shay commented 1 year ago

Hi I need to parse *fastjson.Value value to a string, in case of Number type is there an elegant and fast way check if the value is int number or float number?

func parseFastJsonVal(v *fastjson.Value) string {
    switch v.Type() {
        ...
    case fastjson.TypeNumber:
                 // if it's int number i want to return fmt.Sprintf("%d", v.GetInt())

                // if it's float i want to return fmt.Sprintf("%v", v.GetFloat64())
    }
    return ""
}

I can do naive stuff like checking explicitly if it's float or if it has a decimal point, but i wonder if there is a fastest way to check it based on the data i already got from parsing the JSON