I know there is a proposed standard for JSON schema validation, is the开发者_Python百科re an implementation in .NET?
A free and open-source alternative to Json.NET is NJsonSchema (JSON Schema draft 4).
Json.NET has this functionality.
Add Newtonsoft's Json NuGet Package in your solution. Add below function and pass Schema and your json response in string to below function.
public void ValidateSchema(JsonSchema JSchema, string JsonString) {
JsonString = JsonString.Replace("\"", "'");
var ArrJobj = JArray.Parse(JsonString);
foreach (JObject jo in ArrJobj)
{
if (!jo.IsValid(JSchema)) throw new Exception("Schems Validation failed");
}
}
Hope this helps
Json Everything and its predecesor Manatee.Json are quite good and fast.
NJsonSchema comfortable api however too slow for our use case (schema closing to 100kb the json in 10s of kbs); the above mentioned Manatee and json-everything have a "flag-only" validation mode which is missing here
Newtonsoft (Paid) i have not checked this one
精彩评论