-
Notifications
You must be signed in to change notification settings - Fork 226
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
Feature Request: Optional default argument for $lookup() #732
Comments
This seems like a reasonable enhancement, although it does raise a question which I'll come onto in a bit. However, you can achieve the same result with less code by taking advantage of the sequence flattening rules which will eliminate any non-existent items from the sequence. So if you form an array containing the result of I.e. If you know the name of the key up front (i.e. you don't have to calculate the name in a subexpression), then you can use the See example here where the OrderID of the first Order doesn't exist. Note that this syntax allows you to specify an ordered sequence of several different optional values from arbitrary subexpressions before defaulting to the final value. It's equivalent to the Coming back to your original request, we would need to think about how it would behave if the first argument was an array of objects rather than a single object (https://docs.jsonata.org/object-functions#lookup). It could either:
or
|
@andrew-coleman thanks for the detailed reply. I appreciate it. Using When I submitted this issue, I hadn't thought about the case where object is an array of objects. Option 1 makes most sense. If someone wants option 2, they could use I have a suitable workaround that solves my immediate need. I still think there is merit in Thanks again |
I was introduced to JSONata via Amazon Step Functions. Overall I am enjoying working with it. One missing feature has started to stand out for me.
I'm using
$exists($lookup(object, key)) ? $lookup(object, key) : default
a lot. This would be simplified if$lookup(object, key, default)
was available. Thedefault
argument would be optional and default to undefined.Is this something you would consider adding to JSONata?
The text was updated successfully, but these errors were encountered: