Click or drag to resize
Json.NET Schema

Validate JSON with JToken.IsValid

 

This sample validates a JObject using the IsValid(JToken, JSchema) extension method.

Sample
Usage
JSchema schema = JSchema.Parse(@"{
  'type': 'object',
  'properties': {
    'name': {'type':'string'},
    'hobbies': {
      'type': 'array',
      'items': {'type':'string'}
    }
  }
}");

JObject person = JObject.Parse(@"{
  'name': 'James',
  'hobbies': ['.NET', 'Blogging', 'Reading', 'Xbox', 'LOLCATS']
}");

IList<string> errorMessages;
bool valid = person.IsValid(schema, out errorMessages);

Console.WriteLine(valid);
// true