Click or drag to resize
Json.NET Schema

Auto schema ID generation

 

This sample generates a new JSchema with SchemaIdGenerationHandling set to automatically generate IDs based on the type name.

Sample
Types
public class Person
{
    public string Name { get; set; }
    public int Age { get; set; }
}
Usage
JSchemaGenerator generator = new JSchemaGenerator();

// types with no defined ID have their type name as the ID
generator.SchemaIdGenerationHandling = SchemaIdGenerationHandling.TypeName;

JSchema schema = generator.Generate(typeof(Person));
// {
//   "id": "Person",
//   "type": "object",
//   "properties": {
//     "name": {
//       "type": [ "string", "null" ]
//     },
//     "age": { "type": "integer" }
//   },
//   "required": [ "name", "age" ]
// }