Forum Discussion
avidCoder
7 years agoSuper Contributor
Hey, Would you please try below code:-
import groovy.json.JsonSlurper
def json = '''[
{
"Type": "XXXX",
"Code": "XXXXX",
"ShortName": "ShortName",
"Name": "",
"Description": "",
"DocumentManagementStoreUrl": null,
"IsActive": true,
"EffectiveDate": "2013-12-10T00:00:00",
"TerminationDate": null,
"WasCreatedInError": false,
"DataTimeStamp": "2018-04-30T08:42:45Z"
},
{
"Type": "XXXX",
"Code": "XXXXX",
"ShortName": "ShortName",
"Name": "",
"Description": "",
"DocumentManagementStoreUrl": null,
"IsActive": true,
"EffectiveDate": "2013-12-10T00:00:00",
"TerminationDate": null,
"WasCreatedInError": false,
"DataTimeStamp": "2018-04-30T08:42:45Z"
}
]'''
def code = new JsonSlurper().parseText(json)
log.info codeyou have used some unexpected character "/" because of which you might be getting errors. I have removed these characters from "Name" and "Description" key.
Here is how you will get the output of the above code:-
Mon Apr 30 18:35:23 IST 2018:INFO:[{Code=XXXXX, DataTimeStamp=2018-04-30T08:42:45Z, Description=, DocumentManagementStoreUrl=null, EffectiveDate=2013-12-10T00:00:00, IsActive=true, Name=, ShortName=ShortName, TerminationDate=null, Type=XXXX, WasCreatedInError=false}, {Code=XXXXX, DataTimeStamp=2018-04-30T08:42:45Z, Description=, DocumentManagementStoreUrl=null, EffectiveDate=2013-12-10T00:00:00, IsActive=true, Name=, ShortName=ShortName, TerminationDate=null, Type=XXXX, WasCreatedInError=false}]
rakesh133
7 years agoOccasional Contributor
avidCoder Thanks for your update. Its working fine when I removed the Name and Description fields.
However, for the testing purpose, this is not a feasible solution. I'm receiving this data via an API, I don't have the means to force any form of changing the data on the server side, this data is provided to me as-is.
Could you suggest me a workaround for fixing this issue as I wont be able to manually copy the response and clear the fields each time when I want to run a test.