Reputation: 25631
I know there is a proposed standard for JSON schema validation, is there an implementation in .NET?
Upvotes: 10
Views: 13161
Reputation: 361
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
Upvotes: 3
Reputation: 11858
A free and open-source alternative to Json.NET is NJsonSchema (JSON Schema draft 4).
Upvotes: 17
Reputation: 17
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
Upvotes: 0