From c2553236a74baa66c9d04ffe5bfb492f037bf0c7 Mon Sep 17 00:00:00 2001 From: Cassius0924 <2670226747@qq.com> Date: Wed, 7 May 2025 14:28:30 +0800 Subject: [PATCH] Add IsString and IsNumber helper method --- gjson.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/gjson.go b/gjson.go index a27840f..1462797 100644 --- a/gjson.go +++ b/gjson.go @@ -224,6 +224,16 @@ func (t Result) IsBool() bool { return t.Type == True || t.Type == False } +// IsNumber returns true if the result value is a JSON number. +func (t Result) IsNumber() bool { + return t.Type == Number +} + +// IsString returns true if the result value is a JSON string. +func (t Result) IsString() bool { + return t.Type == String +} + // ForEach iterates through values. // If the result represents a non-existent value, then no values will be // iterated. If the result is an Object, the iterator will pass the key and