From 49373f6a991db22b5eddc9a2eac5cee63d1ee4fb Mon Sep 17 00:00:00 2001 From: Tom <53711814+tbal999@users.noreply.github.com> Date: Thu, 13 Apr 2023 16:52:07 +0100 Subject: [PATCH] fix null bug (#15) Co-authored-by: tbal999 --- jlib/jlib.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/jlib/jlib.go b/jlib/jlib.go index 027a047..37483eb 100644 --- a/jlib/jlib.go +++ b/jlib/jlib.go @@ -57,7 +57,17 @@ func (s StringCallable) toInterface() interface{} { // TypeOf implements the jsonata $type function that returns the data type of // the argument func TypeOf(x interface{}) (string, error) { + if fmt.Sprintf("%v", x) == "" { + return "null", nil + } + v := reflect.ValueOf(x) + + switch x.(type) { + case *interface{}: + return "null", nil + } + if jtypes.IsCallable(v) { return "function", nil } @@ -77,11 +87,6 @@ func TypeOf(x interface{}) (string, error) { return "object", nil } - switch x.(type) { - case *interface{}: - return "null", nil - } - xType := reflect.TypeOf(x).String() return "", fmt.Errorf("unknown type %s", xType) }