-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjsonValidatorExample.txt
More file actions
54 lines (50 loc) · 1.2 KB
/
jsonValidatorExample.txt
File metadata and controls
54 lines (50 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
var schema = """
{
"type": "object",
"required": ["name", "address", "contacts"],
"properties": {
"name": { "type": "string" },
"age": { "type": "integer" },
"address": {
"type": "object",
"required": ["street", "city"],
"properties": {
"street": { "type": "string" },
"city": { "type": "string" },
"zip": { "type": "string" }
}
},
"contacts": {
"type": "array",
"items": {
"type": "object",
"required": ["email"],
"properties": {
"email": { "type": "string" },
"phone": { "type": "string" }
}
}
}
}
}
""";
var data = """
{
"name": "John",
"address": {
"street": "123 Main"
}
}
""";
var validator = new JsonSchemaValidator();
var result = validator.Validate(data, schema);
Console.WriteLine($"Valid: {result.IsValid}");
Console.WriteLine("Missing paths:");
result.MissingPaths.ForEach(p => Console.WriteLine($" - {p}"));
```
**Output:**
```
Valid: False
Missing paths:
- address.city
- contacts