Validating JSON?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2017 11:19 PM
Hi Experts,
I am trying to find out if the JSON we are getting from REST is validate or not?
we are getting few rows in JSON response but one of the row is terminated incorrectly, if i want to do some validation from my side do we have any solution for this?
Regards,
Amol Bavaskar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2017 11:27 PM
Hi Amol,
Could you please explain what do you mean by "terminated". Does it mean some properties are missing?
if that is the case, iterator over properties might be helpful to check if property exists against object or not.
somethins like if ( typeof objectOfYours['propertyName'] != undefined )
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2017 11:40 PM
Hi Deepak,
It is like
{
"RequestDetails": {
"ROW": [
{
"REQUEST_ID": "94092",
"CCR_TRANS_ID": "null",
"REQUEST_VERSION_ID": "796231",
"RESERVATION_ID": "1079056",
"REQ_STATUS": "Confirm",
"REQUEST_TYP_NM": "STANDARD TEST",
"CUSTOMER_ID": "18910",
"CUSTOMER_NM": "ITSCE TMT ("CO",
"START_DATE": "09/25/2017",
"START_TIME": "8",
"TIME_ZONE_TEST": "EST",
"EARLIEST_CONFIRM_OR_HELD_DATE": "11/10/2016",
"ARS_R2C_SR": "n",
"ARS_R2C_SRM": "n",
"ARS_R2C_EVAULT": "n",
},
{
"REQUEST_ID": "94092",
"CCR_TRANS_ID": "null",
"REQUEST_VERSION_ID": "796231",
"RESERVATION_ID": "1079056",
"REQ_STATUS": "Confirm",
"REQUEST_TYP_NM": "STANDARD TEST",
"CUSTOMER_ID": "18910",
"CUSTOMER_NM": "ITSCE TMT ("CO")",
"START_DATE": "09/25/2017",
"START_TIME": "8",
"TIME_ZONE_TEST": "EST",
"EARLIEST_CONFIRM_OR_HELD_DATE": "11/10/2016",
"ARS_R2C_SR": "n",
"ARS_R2C_SRM": "n",
"ARS_R2C_EVAULT": "n",
}, {
"REQUEST_ID": "94092",
"CCR_TRANS_ID": "null",
"REQUEST_VERSION_ID": "796231",
"RESERVATION_ID": "1079056",
"REQ_STATUS": "Confirm",
"REQUEST_TYP_NM": "STANDARD TEST",
"CUSTOMER_ID": "18910",
"CUSTOMER_NM": "ITSCE TMT ("CO")",
"START_DATE": "09/25/2017",
"START_TIME": "8",
"TIME_ZONE_TEST": "EST",
"EARLIEST_CONFIRM_OR_HELD_DATE": "11/10/2016",
"ARS_R2C_SR": "n",
"ARS_R2C_SRM": "n",
"ARS_R2C_EVAULT": "n",
}, {
"REQUEST_ID": "94092",
"CCR_TRANS_ID": "null",
"REQUEST_VERSION_ID": "796231",
"RESERVATION_ID": "1079056",
"REQ_STATUS": "Confirm",
"REQUEST_TYP_NM": "STANDARD TEST",
"CUSTOMER_ID": "18910",
"CUSTOMER_NM": "ITSCE TMT ("CO")",
"START_DATE": "09/25/2017",
"START_TIME": "8",
"TIME_ZONE_TEST": "EST",
"EARLIEST_CONFIRM_OR_HELD_DATE": "11/10/2016",
"ARS_R2C_SR": "n",
"ARS_R2C_SRM": "n",
"ARS_R2C_EVAULT": "n",
}
]}
}
this is my JSON response which is terminated incorrectly as highlighted so at the time of processing it is escaping the records below that.
i want to do some exception handling at our side how can we do that?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-29-2017 12:21 AM
Hi Amol,
Following links might help you:
JSON Object validation in Javascript - Stack Overflow
javascript - How to test if a string is JSON or not? - Stack Overflow
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-29-2017 12:28 AM
Hi Ankur,
I already gone through these links. it is not applicable in my case.
or if you have any idea how can we parse can you please explain it will be more appreciated.
Regards,
Amol