isValid() is not overloaded?

Jan 21, 2011 at 9:24 AM

Hi guys,

I'm using Json schema feature in to validate the schema of my RESTful API responses.  However when I use the isValid() method to valid I only see one version of this method that returns a bool.  According to James' post ( this method should be overloaded to also return the position of the error is one occurs.  

With this code I am only seeing one option i.e. no overloads for isValid(). Is there something I'm missing here?  Thanks.

using Newtonsoft.Json; 
using Newtonsoft.Json.Linq; 
using Newtonsoft.Json.Schema; 

// And other MS and NUnit references that I need to get this working. JsonSchema schema; 

// Read json schema 
using (var streamReader = new StreamReader(schemaFile) {
schema = JsonSchema.Parse(streamReader.ReadToEnd()); 

// Call RESTful API 
var request = WebRequest.Create(RestfulAPICall) as HttpWebRequest; 

// Get response and validate against schema 
using (var response = request.GetResponse().GetResponseStream()) { 
var responseString = new StreamReader(response).ReadToEnd();
var jsonResponse = JObject.Parse(responseString);
Assert.That(jsonResponse.IsValid(schema), Is.True); 



Jan 5, 2012 at 10:18 PM

I have the same problem!

I've tried this approach but it fails.  I have no idea if Json.Net supports error messages at all, how do I get some message back that says why the validation failed?



SHouldn't it throw an exception with information?  Or

I'm working with this:


    JObject person = JObject.Parse(@"{
              ""Major"": 3,
              ""Minor"": 5,
              ""Build"": 0,
              ""Revision"": 2,
              ""MajorRevision"": 0,
              ""MinorRevision"": 2
            // what is perosn.Value?

           // person.Validate(schema);    // Valid(schema);
            } catch (Exception ex){

THere seems to be no way of getting an error message though it's either Person.IsValid == true or == false

How do I get an error message back from

Please help!