diff --git a/pkg/exprparser/functions.go b/pkg/exprparser/functions.go index 64103e0..37a38db 100644 --- a/pkg/exprparser/functions.go +++ b/pkg/exprparser/functions.go @@ -151,7 +151,7 @@ func (impl *interperterImpl) join(array reflect.Value, sep reflect.Value) (strin func (impl *interperterImpl) toJSON(value reflect.Value) (string, error) { if value.Kind() == reflect.Invalid { - return "", nil + return "null", nil } json, err := json.MarshalIndent(value.Interface(), "", " ") diff --git a/pkg/exprparser/functions_test.go b/pkg/exprparser/functions_test.go index bdae533..3c3d347 100644 --- a/pkg/exprparser/functions_test.go +++ b/pkg/exprparser/functions_test.go @@ -137,6 +137,7 @@ func TestFunctionToJSON(t *testing.T) { name string }{ {"toJSON(env) }}", "{\n \"key\": \"value\"\n}", "toJSON"}, + {"toJSON(null)", "null", "toJSON-null"}, } env := &EvaluationEnvironment{