Using Json.NET attributes |
This sample generates a new JSchema from a .NET type with Json.NET serialization attributes.
public class User { // always require a string value [JsonProperty("name", Required = Required.Always)] public string Name { get; set; } // don't require any value [JsonProperty("role", NullValueHandling = NullValueHandling.Ignore)] public string Role { get; set; } // property is ignored [JsonIgnore] public string Password { get; set; } }
JSchemaGenerator generator = new JSchemaGenerator(); JSchema schema = generator.Generate(typeof(User)); // { // "type": "object", // "properties": { // "name": { // "type": "string" // }, // "role": { // "type": [ // "string", // "null" // ] // } // }, // "required": [ // "name" // ] // }