The CreatorCon Call for Content is officially open! Get started here.

Validating JSON?

IamAmolB
Tera Guru

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

10 REPLIES 10

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


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

I second what Ankur is saying, it is the source where this needs to be fixed and checked if they are sending proper data.


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


"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




Kalaiarasan Pus
Giga Sage

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?