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-29-2017 12:39 AM
Hi Amol,
If this JSON response you are receiving by consuming some third party API then it is there look out to send valid JSON string so that it can be easily parsed in ServiceNow.
I will recommend you to inform them to send valid JSON string in API response because that is a standard in REST. Since they are responsible for sending the response then it should be in valid format. There is no point in validating in ServiceNow.
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:54 AM
I second what Ankur is saying, it is the source where this needs to be fixed and checked if they are sending proper data.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-29-2017 01:28 AM
True JSON should be correct from the sender.
but what i am trying to validate is if the JSON is not correct it should auto correct by syntax or it should skip that row and process remaining records.
Regards,
Amol
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-29-2017 01:43 AM
"CUSTOMER_NM": "ITSCE TMT ("CO",
I guess you are trying to figure out why ending brace ) is missing in above value.
If you have to do it, you can check for property value like
Iterated over Row array in for loop and say
RequestDetails.row[i].CUSTOMER_NM.indexOf(")")) == -1

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-29-2017 01:11 AM
When I read the thread, it isn't clear what you are trying to do? Do you want to know how to parse the data or check if it is a valid Json object? And when you mean valid, are you trying to verify the correctness of information or the formatting of information?