Validate JSON with JToken.IsValid |
This sample validates a JObject using the IsValid(JToken, JsonSchema) extension method.
Caution |
---|
Obsolete. JSON Schema validation has been moved to its own package. See https://www.newtonsoft.com/jsonschema for more details. |
JsonSchema schema = JsonSchema.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