cancel
Showing results for 
Search instead for 
Did you mean: 

Substring a field inside of an array?

bill_sturdivant
New Contributor III

I’m trying to substring the field $studySiteChecklist.checklist.lastUpdateDate but I can get it to keep the same output as the input.

Any ideas?

[{
	"country": "a",
	"studySiteChecklist": {
		"checklist": [{
			"lastUpdateDate": "2017-08-27T00:00:00Z",
			"commentsIndicator": "0",
			"comments": "0",
			"yesNoIndicator": "0",
			"questionNumber": "0",
			"checkListNumer": "0",
			"question": "0"
		}, {
			"lastUpdateDate": "2000-08-27T00:00:00Z",
			"commentsIndicator": "0",
			"comments": "0",
			"yesNoIndicator": "0",
			"questionNumber": "0",
			"checkListNumer": "0",
			"question": "0"
		}]
	}
}]

Output needed:

[{
	"country": "a",
	"studySiteChecklist": {
		"checklist": [{
			"lastUpdateDate": "2017-08-27",
			"commentsIndicator": "0",
			"comments": "0",
			"yesNoIndicator": "0",
			"questionNumber": "0",
			"checkListNumer": "0",
			"question": "0"
		}, {
			"lastUpdateDate": "2000-08-27",
			"commentsIndicator": "0",
			"comments": "0",
			"yesNoIndicator": "0",
			"questionNumber": "0",
			"checkListNumer": "0",
			"question": "0"
		}]
	}
}]
9 REPLIES 9

tlikarish
Employee
Employee

In a Mapper snap you can set the Mapping Root to the array, which can sometimes make writing expressions easier. Take a look at this example and let me know if it helps.

image

Wow, I never used the pass through with mapping root. I was able to get it to work.
image

Thank you!
Bill

psathyanarayan
Employee
Employee

I think @tlikarish suggestion is a good one. Another option would be is to use the map method that is available within an array object. If you want to conditionally update elements in the array you can use the if condition within the update expression of the map method.

I have tried mapping already with the following.

jsonPath($, “$studySiteChecklist.checklist[*].lastUpdateDate”).map(x => x.substr(0,10)).toString()
image

But I got the follwing which is not correct.

image

Thank you for the suggestion
Bill