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

psathyanarayan
Employee
Employee

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.

image

psathyanarayan
Employee
Employee

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.

psathyanarayan
Employee
Employee

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

bill_sturdivant
New Contributor III

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