cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a better way to simply convert an array to a string?

acesario
Contributor II

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:
image

8 REPLIES 8

acesario
Contributor II

That worked, thank you for the getfirst syntax and idea. I dont mean to complain, just that this requires multiple steps per mapper row and more time and potential for human error. I have to 1. Map the field. 2. Copy the field from snaplogic to text editor 3. review the path, and 4. make adjustments to include the get first. Copy/paste back into the field in snap. (I copy out of snap because the editor window is to tight to work with.)
This is actually more time than using [0]. Is there any advantage to using mapfirst rather than jsonpath [0]?

I think I answered my own question on the downside of using [0] in a mapper, if the value is null, the expression will fail.

Yeah with null safe access enabled especially it is a safer expression was my thought. I can’t see any ways to save any time from establishing/developing these mappings necessarily.

acesario
Contributor II

@cjhoward18 interestingly, when i get data where the node does not exist (never for date of birth or name, but some other data elements) the .getfirst fails, even when using a hasOwnProperty. I ended up going back to my original pathing, with the following syntax.

$.hasOwnProperty(“jsonPath($, ‘$Student[0].Student_Data[0].Student_Person_Data[0].Personal_Profile_Data[0].Gender_Reference.ID.Gender_Code’)”) ? jsonPath($, ‘$Student[0].Student_Data[0].Student_Person_Data[0].Personal_Profile_Data[0].Gender_Reference.ID.Gender_Code’): ‘-’