Substring a field inside of an array?

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"
		}]
	}
}]

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.

1 Like

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.

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

Thank you!
Bill

I have tried mapping already with the following.

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

But I got the follwing which is not correct.

image

Thank you for the suggestion
Bill

It is weird that it is concatenating to the existing value. Should the toString() be applied at the end? This is because substr() is already returning a string.

I tried toString because lastUpdateDate was being returned the same way but as it was an Array.

Then it must be something to do with the interaction of json with arrays. Probably the only way it would work is to delete the key value pair and insert it back again with the key value pair, but with the newly updated value and the key value remaining the same.

Another aspect may be due to immutability property of the string object.

Not sure, but I was able to get it to work with the first suggestion.