This schema validator is built using Json.NET Schema and C#.
public class JsonSchemaController : ControllerBase
{
[HttpPost]
[Route("api/jsonschema/validate")]
public ValidateResponse Validate(ValidateRequest request)
{
// Load schema
JSchema schema = JSchema.Parse(request.Schema);
JToken json = JToken.Parse(request.Json);
// Validate json
IList<ValidationError> errors;
bool valid = json.IsValid(schema, out errors);
// Return error messages and line info to the browser
return new ValidateResponse
{
Valid = valid,
Errors = errors
};
}
}
public class ValidateRequest
{
public string Json { get; set; }
public string Schema { get; set; }
}
public class ValidateResponse
{
public bool Valid { get; set; }
public IList<ValidationError> Errors { get; set; }
}
Get Json.NET Schema from NuGet (recommended) or download a ZIP of the assemblies and source code:
Json.NET Schema
PM> Install-Package Newtonsoft.Json.Schema