12-06-2021 09:00 AM
Hi,
I’m trying to reference a value from the input object in the JSON Generator snap. The property is optional in the upstream snaps. If I straight reference it, I’ll get an “Invalid JSON-Path field not found” error.
Is there a similar way to the use “null-safe access” option like in the mapper snap in the JSON Generator snap?
Is there a way to use the $.get() method in the JSON Generator snap? I keep getting syntax errors.
Below is my property reference:
$['wd:Project_Data']['wd:End_Date']
This fails:
$['wd:Project_Data'].get("wd:End_Date")
$['wd:Project_Data'].get(['wd:End_Date'])
$.get(['wd:Project_Data']['wd:End_Date'])
Solved! Go to Solution.
12-07-2021 12:03 PM
@Charles,
Like Patrick, I was also thinking Velocity (VTL) as a solution, but as I tried to solution your original post, the Workday namespace convention in the property names adds some complexity. I don’t know if Velocity beats the null-safe mapper for your particular use case, but it can be good info for your tool belt in the future.
The kind of ugly solution I came up with (in a one-liner) is:
[
{
"output" : #set ($pd = $['wd:Project_Data']) #set ($ed = $pd['wd:End_Date']) #if (${ed}) ${ed} #else null #end
}
]
I’m not well versed in VTL, so there’s likely something a little cleaner than the above.
12-07-2021 12:28 PM
@del, really appreciate the working example, thank you! Like you mention, I don’t think VTL outweighs putting in a mapper snap, but really glad to learn about VTL as a tool for potential future solutions. I guess I’ll have to read up on that a bit. Thank you for the start!