10-14-2020 05:02 AM
When I do a get from a given web service, I often have a single value being returned, but within an array. What happens is I end up with this type of output [“Andrew”] rather than say “Andrew”
In order to write this value, always the 0 level value I end up hacking it with something like the path for the first values.
jsonPath($, “$Student**[0]**.Student_Data[0].Student_Person_Data[0].Personal_Profile_Data[0].Date_of_Birth”)
Here is a screenshot of the input schema for reference:
10-14-2020 05:13 AM
Just a comment on the impact to productivity… I have between 40 and 70 fields to map, multiplied by an average of 4 changes to the mapper to include the 0. So any real time savings of no code, gets eaten up with this tedious manual task. I also worry about using [0] in this fashion, as I was taught that this is bad practice in xslt/xpath.
10-14-2020 06:34 AM
Hi @acesario
I think the getFirst() method could help your scenario.
I think the expression using getFirst() with your example would look something like this:
$.getFirst(‘Student’).getFirst(‘Student_Data’).getFirst(‘Student_Person_Data’).getFirst(‘Personal_Profile_Data’).Date_of_Birth
This relies on those fields always being present and arrays. If there are times that is not true additional logic will be needed.
10-14-2020 06:52 AM
Thank you for your response @cjhoward18.
However, my snap seems to be requiring jsonpath… if I do a getFirst (‘Student’) as prescribed I get a ‘could not compile expression’ error as shown:
This seems to happen sometimes when pulling from a web service, where the response is structured as array [*] object. I had tried a get in places across my pipeline, and hit similar issues. Im unclear on the usage and why this occurs, but get/getfirst seem limited to certain objects.
10-14-2020 06:55 AM
@acesario Sorry I forgot to format the expression so the quotes got bad formatting. Try this expression correctly formatted:
$.getFirst('Student').getFirst('Student_Data').getFirst('Student_Person_Data').getFirst('Personal_Profile_Data').Date_of_Birth