-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
User-defined functions #29
Comments
https://github.com/jmespath/jmespath.py, already supports user defined functions - anyway it can be supported in this repo as well? |
What's the use case for user-defined functions? The most important design decision of JMESPath is that all changes start with the spec and that it's language-agnostic. User defined functions deviate from both of these benefits. |
There can be usecases where we need regex, client should allow the user to extend JMESpath if they wish. Also if its against design decision why is part of some of the clients such as the python client. |
I've seen two benefits:
|
Exactly, |
Regex is a use case that we are after as well. |
@mtdowling are you open to taking a PR to make it possible to add a custom function? Here is a test case for what I had in mind: func TestCustomFunction(t *testing.T) {
assert := assert.New(t)
data := make(map[string]interface{})
data["foo"] = "BAR"
precompiled, err := Compile("to_lower(foo)")
precompiled.Register(&FunctionEntry{
Name: "to_lower",
Arguments: []ArgSpec{
{Types: []JpType{JpString}},
},
Handler: func (arguments []interface{}) (interface{}, error) {
s := arguments[0].(string)
return strings.ToLower(s), nil
},
})
assert.Nil(err)
result, err := precompiled.Search(data)
assert.Nil(err)
assert.Equal("bar", result)
} |
For others who may need this, here is my fork with the custom function support: https://github.com/kyverno/go-jmespath/. |
Gotta say, this one baffled me, why we couldn't simply add a compare date function for ISO 8601 formatted strings due to the spec stating that > < etc are numerical only. This really limits our choices and forces us to do one of:
You can guess which option we chose. |
@JimBugwadia we at JMESPath Community would like to do just that: create a community around the language. To this end, we will need official maintainers of the various implementations. Would you like to take over the latest version and become official maintainer for the Go implementation? This version has most bug fixes from issues here and is up to standards with our spec. It "only" lacks third-party functions 😉 |
Hi @springcomp I discussed this with my colleagues @eddycharly @realshuting @chipzoller and we are open to becoming the official maintainers of the Go implementation. @eddycharly has already created a draft PR for the custom functions support. |
Awesome, please, let me welcome you to JMESPath Community and give you access rights to the repository. |
Could be great if one could extend default function list with their own functions.
The text was updated successfully, but these errors were encountered: