diff --git a/README.md b/README.md index 0d62be7..7657794 100644 --- a/README.md +++ b/README.md @@ -119,6 +119,7 @@ There are a variety of handy functions that work on a result: ```go result.Value() interface{} result.Int() int64 +result.Uint() uint64 result.Float() float64 result.String() string result.Bool() bool diff --git a/gjson.go b/gjson.go index 01c15aa..eac523c 100644 --- a/gjson.go +++ b/gjson.go @@ -108,6 +108,21 @@ func (t Result) Int() int64 { } } +// Uint returns an unsigned integer representation. +func (t Result) Uint() uint64 { + switch t.Type { + default: + return 0 + case True: + return 1 + case String: + n, _ := strconv.ParseUint(t.Str, 10, 64) + return n + case Number: + return uint64(t.Num) + } +} + // Float returns an float64 representation. func (t Result) Float() float64 { switch t.Type {