- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2023 11:12 PM
I have a scripted REST api and now I am trying to get the payload if it is a valid then I am able to get it as below
var payload = request.body.data;
But if third party system send invalid JSON to ServiceNow then how to capture that I have tried different ways but not able to get it.
Below is the example of invalid JSON but I am trying to get it.
{
"Data": {
"Name": "test",
"ID": "1500"
"description": "Test description"
}
}
Share any solution if it is possible to get in any way.
Thanks in advance!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2023 04:16 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2023 01:21 AM
Hi @Prabu Velayutha ,
Yes i tried not working. I think because it is not a valid json.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2023 01:02 AM
What should be the valid JSON? please provide some examples
If my answer solved your issue, please mark my answer as ✅ Correct & 👍Helpful based on the Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2023 01:09 AM
Hi @Prince Arora ,
{
"Data": {
"Name": "test",
"ID": "1500"
"description": "Test description"
}
}
Take this as a example after id comma is missing so it will be invalid JSON. Even it is missing comma i need to get it on scripted REST API.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2023 01:25 AM
You can do one thing for example:
try{
var data = JSONData; // lets just say its the invalid one
data = JSON.parse(data); // you need to do parsing for using the data for your scripting,
if data is invalid it will through some errors and you can catch those errors in the catch block.
}catch(ex){
var res = {};
res["status"] = "Error";
res["message"] = ex.message;
response.setBody(JSON.stringify(res)); // sending the invalid message back
}
I hope you understand!
If my answer solved your issue, please mark my answer as ✅Correct & 👍Helpful based on the Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2023 01:50 AM
Hi @Prince Arora ,
Errors I am able to do but I am trying to capture that invalid payload.