Skip to content

Commit

Permalink
fix null bug (#15)
Browse files Browse the repository at this point in the history
Co-authored-by: tbal999 <[email protected]>
  • Loading branch information
tbal999 and tbal999 authored Apr 13, 2023
1 parent 928dc02 commit 49373f6
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions jlib/jlib.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) == "<nil>" {
return "null", nil
}

v := reflect.ValueOf(x)

switch x.(type) {
case *interface{}:
return "null", nil
}

if jtypes.IsCallable(v) {
return "function", nil
}
Expand All @@ -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)
}

0 comments on commit 49373f6

Please sign in to comment.