Have the following JSON:
def jsonString = '{"studyDTO":{"studyId":191,"studyCode":"test_ispptest2"},"sites":[{"studyId":191,"siteRecid":16521,"siteId":"11001"}],"allSubjects":true,"states":null,"visits":[{"studyId":191,"visitSubmitName":"baseline","visitDisplayName":"Baseline","orderOfDisplay":10}],"modalities":null,"examDates":null,"series":null,"transferType":null,"sftpLocations":[],"dicomLocations":[],"fileSystemLocations":[],"rawFileSystemLocations":[],"customFolder":null,"folderStructure":null,"customFile":null,"fileStructure":null,"includePS":null}'
Want to update the value for "orderOfDisplay":10
with an integer from a data source dynamically.
def jsonConvert = new JsonSlurper();
def object = jsonConvert.parseText(jsonString);
def builder = new JsonBuilder(object)
builder.content.visits[0].orderOfDisplay = 23
[23 is only for example. I am running this for 10 times and every time the value is expected to change]
log.info(builder.toPrettyString());
similar to the post here, but in my case, I am trying to update an integer.
The error that I am getting after the update is,
{
"studyDTO": {
"studyId": 191,
"studyCode": "test_ispptest2"
},
"sites": [
{
"studyId": 191,
"siteRecid": 16521,
"siteId": "11001"
}
],
"allSubjects": true,
"states": null,
"visits": [
{
"studyId": 191,
"visitSubmitName": "cycle_1",
"visitDisplayName": "Cycle 1",
"orderOfDisplay": "23"
}
],
"modalities": null,
"examDates": null,
"series": null,
"transferType": null,
"sftpLocations": [
],
"dicomLocations": [
],
"fileSystemLocations": [
],
"rawFileSystemLocations": [
],
"customFolder": null,
"folderStructure": null,
"customFile": null,
"fileStructure": null,
"includePS": null
}
the value 23 is going in quotes