var schema = new JsonSchema4 { Type = JsonObjectType.Object, Properties = { ["name"] = new JsonProperty { Type = JsonObjectType.String }, ["age"] = new JsonProperty { Type = JsonObjectType.Integer, Minimum = 0 } } }; var schemaJson = schema.ToJson();
var subSchema = new JsonSchema4 { Type = JsonObjectType.String, Enum = new [] { "red", "green", "blue" } }; var schema = new JsonSchema4 { Type = JsonObjectType.Object, Properties = { ["name"] = new JsonProperty { Type = JsonObjectType.String }, ["color"] = new JsonProperty { Ref = subSchema } } }; var schemaJson = schema.ToJson();In this example, a JsonSchema4 object is created with an object type and two properties: name (string type) and color (referenced schema defined in the subSchema variable). The ToJson method is then executed on this object, resulting in a JSON string representation of the schema. This library belongs to the Newtonsoft.Json.Schema package.