I am using NewtonSoft.JSON to do some JSON schema validation. I am seeing that the validation is returning "ISValid=true" if the JSON has additional data than what is specified in the schema. Code and data is below. the schema does not have a property definition for a property called "city", the JSON data coming is has the property and a value for it. I expect the IsValid call below to return false, But it returns true. Is there a setting on the schema or on the classsuch as "Enforce strict" or something similar which will enforce that the data has all and only the dataas specified in the schema?
public static void ValidateJsonSchema(string expectedSchema, string actualData)
{
JsonSchema validSchema = JsonSchema.Parse(expectedSchema);
JObject actualJson = JObject.Parse(actualData);
IList<string> messages;
if (!actualJson.IsValid(validSchema, out messages))
{
throw new Exception("Returned data JSON schema validation failed." + messages.ToXml());
}
}