Click or drag to resize
Json.NET Schema

Using JSchemaUrlResolver

 

This sample uses a JSchemaUrlResolver to resolve schema references from different JSON documents.

Sample
Usage
// resolver will fetch 'http://schema.org/address.json' with a web request as the parent schema is loaded
JSchemaUrlResolver resolver = new JSchemaUrlResolver();

JSchema schema = JSchema.Parse(@"{
  'type': 'object',
  'properties': {
    'name': {'type':'string'},
    'addresses': {
      'type': 'array',
      'items': {'$ref': 'http://schema.org/address.json'}
    }
  }
}", resolver);

JToken json = JToken.Parse(@"{
  'name': 'James',
  'addresses': [
    {
      'line1': '99 Smithington Street',
      'line2': 'Real Town',
      'country': 'USA'
    }
  ]
}");

IList<string> errorMessages;
bool isValid = json.IsValid(schema, out errorMessages);