public static void Main()
""genericId"": ""abcdefghijk"",
""heartbeatId"": ""abcdefghijk"",
""components"": [{""prop1"":""foobarfoo"", ""prop2"":84}]
var jsonDocumentInstance = JsonDocument.Parse(json);
var schemaText = JsonSerializer.Serialize(Schemas.GenericSchema);
var schemaFromString = JsonSchema.FromText(schemaText);
var evaluationResultFromSchema = schemaFromString.Evaluate(jsonDocumentInstance);
var directEvaluationResult = Schemas.GenericSchema.Evaluate(jsonDocumentInstance);
Console.WriteLine(evaluationResultFromSchema.IsValid);
Console.WriteLine(directEvaluationResult.IsValid);
static readonly JsonSchema SunComponent = new JsonSchemaBuilder()
.Properties(new Dictionary<string, JsonSchema>
{ "prop1", new JsonSchemaBuilder()
.Type(SchemaValueType.String)
{ "prop2", new JsonSchemaBuilder()
.Type(SchemaValueType.Number)
.AdditionalProperties(false);
public static readonly JsonSchema GenericSchema = new JsonSchemaBuilder()
.Type(SchemaValueType.Object)
.Schema(MetaSchemas.Draft7Id)
.Properties(new Dictionary<string, JsonSchema>
"genericId", new JsonSchemaBuilder()
.Type(SchemaValueType.String)
.Description("A unique identifier for the device and connected infrastructure.")
"heartbeatId", new JsonSchemaBuilder()
.Type(SchemaValueType.String)
.Description("Heartbeat ID of the device.")
"components", new JsonSchemaBuilder()
.Type(SchemaValueType.Array)
.Items(new JsonSchemaBuilder().OneOf(
new JsonSchemaBuilder().Ref(new Uri("#/$defs/sunComponent",
UriKind.RelativeOrAbsolute))))
.Defs(new Dictionary<string, JsonSchema>
{ "sunComponent", SunComponent},
"heartbeatId", "components")
.AdditionalProperties(false);