I get user input which I need to store in a database field of the JSON-type. This can be anything and may be anything as long as it is valid JSON. In JSON.net there is a way to validate JSON against a JSON scheme but that is too specific.
Now I have to deserialize the JSON string and use a try-catch for this and I rather do a simple:
JsonTextReader rJSonReader = new JsonTextReader(new StringReader(@sCellValue));
if (rJSonReader.isValid()) {#more code here;}
This would be much cleaner I think. Or am I wrong?
I'd suggest writing an extension method, analogous to TryParse for e.g. int. Do a try/catch inside, write to provided variable and return if the operation was succesful.
You could write your own Json syntax validator, but that seems like spending way to much time on a problem that is not really a problem :)