-
Notifications
You must be signed in to change notification settings - Fork 54
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
Is there any way we can work with custom function output in a "normal" json way? #272
Comments
Hmm, I would say that it should be possible... what version are you using? |
This is working: { "result": "#returnToken()" } JUSTContext context = new JUSTContext();
context.RegisterCustomFunction(null, "JUST.UnitTests.Token", "ReturnJToken", "returnToken"); namespace JUST.UnitTests
{
public class Token
{
public Newtonsoft.Json.Linq.JToken ReturnJToken()
{
return Newtonsoft.Json.Linq.JToken.Parse("{ \"fn\": 1 }");
}
}
} { "result": { "fn": 1 } } |
And this too (apply a transformation over another input): { "result": "#applyover(#returnToken(),'#valueof($.fn)')" } |
Thanks for the fast response. I am using Perhaps I need to be more explicit about "normal" and what I'm doing/trying do do. We have an application (Salesforce Event Listener) which listens to Salesforce Platform Events and then will reshape and redistribute them to multiple Azure Service Bus Topics both to mitigate Salesforce limits and obscure Salesforce implementation details. One Salesforce limitation we are overcoming on the Salesforce side is that Platform Events can't have a very sophisticated structure. All fields live at the same level, with no embedded objects or arrays. To overcome this, the developers on the Salesforce side are serializing objects and arrays and putting these into Text Areas (long strings). I have this custom function, which works, to "normalize" these embedded Jsons by removing the quotes
I can use a template to invoke it like:
The problem comes if I want to dig some deeper values out of this. If I want to get the Order Number for the first line, I would like to be able to do this:
However, currently, I need to do:
where You can see, that looks pretty ugly, and could get much worst depending on the complexity of the value(s) we are deserializing.... and then we might sometimes want/need to pull out multiple values.... |
Try this { "result": "#applyover(#tryunquote(#valueof($.data.payload.OpportunityLineItems__c)),'#valueof($[0].OrderNumber__c)')" } The result of #tryunquote will be the input for next argument/transformer (#valueof(...)). You can also loop through the result of #tryunquote, if it is an array: { "result": "#applyover(#tryunquote(#valueof($.data.payload.OpportunityLineItems__c)),{ '#loop($)': { 'curr': '#currentvalue()' } })" } If the second argument is a scalar/single result function, then quotes are needed around it (single quotes to distinguish between argument and a whole JUST expression), if it is an object, single quotes are only needed around that object's properties (and values if they are strings). #265 / #267 can be handy, avoid escaping characters if second argument (sceond transformation) for #applyover becomes too big and cumbersome. |
Cheers for this! If I understand #265/#267 correctly, there should be a way I could capture the result from (Til now, my use of JUST has been emphatically "Simple" though I can see that changing in the near future.) |
For "scalar/simple" I mean the result being a string, a number, a boolean... not a JObject/Jarray. |
Just having 2 new functions like toString and toJson would help in such scenarios I guess. These functions can serialize JSON object to string and string to JSON. This addition would be helpful in many scenarios. Please let me know if i can help and create pull requests to add these 2 functions. |
I have some custom functions which I expect to return
JToken
.I would like to be able to simply treat these results as if they were embedded json and then use similar notations to get either indexed values or named properties.
Either I'm missing something or this is not presently possible.
As a work around I've implemented methods can return the values I need and this seems to work, but in practice, it reduces the readability of our templates.... I can't help feeling there should be a better way.
The text was updated successfully, but these errors were encountered: