Forum Discussion
Apologies for not adding the JSON Response. Please see below the JSON Response array I am receiving for the service
[ { "Type": "XXXX", "Code": "XXXXX", "ShortName": "ShortName", "Name": "Long Name (Including Special Characters like ',-,\," etc)", "Description": "Description of the Service Agreement (Including Special Characters like ',-,\," etc)"", "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": "Long Name (Including Special Characters like ',-,\," etc)", "Description": "Description of the Service Agreement (Including Special Characters like ',-,\," etc)"", "DocumentManagementStoreUrl": null, "IsActive": true, "EffectiveDate": "2013-12-10T00:00:00", "TerminationDate": null, "WasCreatedInError": false, "DataTimeStamp": "2018-04-30T08:42:45Z" }, { ..... }, { ..... }, ]
- avidCoder7 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 code
you 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}]
- rakesh1337 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.
- avidCoder7 years agoSuper Contributor
Hi Rakesh,
Whatever Json you have mentioned above is not correct. There is some problem with the special characters being used there.
Attached is the screenshot for the reference. Please fix the Json problem first. Ultimately, that issue will be resolved.
Thanks.
avidcoder
Related Content
- 4 years ago
- 9 years ago
Recent Discussions
- 15 years ago