I want to check if the text the user enters is really JSON. I know that I can easily do this using something like this:
function IsJsonString(str) { try { JSON.parse(str); } catch (e) { return false; } return true; }
My problem is the JSON that comes from Mongo, which is wrapped in ObjectId , ISODate , ie:
{ "_id" : ObjectId("5733b42c66beadec3cbcb9a4"), "date" : ISODate("2016-05-11T22:37:32.341Z"), "name" : "KJ" }
This is not valid JSON. How can I validate JSON by assuming something like above?
json javascript validation mongodb
Kj3
source share