I'm trying to validate my json file but my validation doesn't work properly. Please help me to understand what is wrong.
public static bool ValidJson(string jasonData)
{
string myJson = @"{
'description': 'rehber',
'type': 'object',
'properties':
{
'isim': {'type':'string', 'required': true },
'tel': {'type':'string','required': true},
},
'additionalProperties': false
}";
JsonSchema schema = JsonSchema.Parse(myJson);
JToken rehber = JToken.Parse(jasonData);
bool valid = rehber.IsValid(schema);
return valid;
}
jasonData that comes to ValidJson function is like that:
"[\n {\n \"isim\": \"Ahmet\",\n \"tel\": \"+46 637 530 68 94\"\n },\n {\n \"isim\": \"Mahmet\",\n \"tel\": \"+46 637 530 68 91\"\n }\n]"
I changed my schema but it shows true all the time. I don't want additional fields in my json file and null values. But this schema doesn't work properly either.
string myJson = @"{
'type': 'array',
'title': 'The root schema',
'description': 'The root schema comprises the entire JSON document.',
'additionalItems': false,
'items': {
'allOf': [
{
'type': 'object',
'title': 'The first anyOf schema',
'description': 'An explanation about the purpose of this instance.',
'required': [
'isim',
'tel'
],
'additionalProperties': false,
'properties': {
'isim': {
'type': 'string',
},
'tel': {
'type': 'string',
}
}
}
],
}
}";