'Validate JSON against a schema in .NET

I know there is a proposed standard for JSON schema validation, is there an implementation in .NET?



Solution 1:[1]

A free and open-source alternative to Json.NET is NJsonSchema (JSON Schema draft 4).

Solution 2:[2]

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

Solution 3:[3]

  • 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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rico Suter
Solution 2 Gurunath Navale
Solution 3