0

I have json schema and value to compare against it. I have implemented it using Newtonsoft.Json.Schema. But now realised that it is not for free use. I then tried to implement is using NJsonScehma nuget package but now getting the below error on last line of code.

cannot convert from 'Newtonsoft.Json.Linq.JToken' to 'Newtonsoft.Json.Schema.JsonSchema'

Below is my code. Any idea how to resolve this. TIA.

var jsonSchema = JObject.Parse(schemafile);  //schema definition
JToken json = JToken.Parse(value);//value to validate against schema
var result = jsonSchema.Validate(json);

2 Answers2

0

My validator, JsonSchema.Net, is built on System.Text.Json. It's part of a larger suite called json-everything. You can read the docs here.

I'm also one of the authors of the JSON Schema spec.

gregsdennis
  • 7,218
  • 3
  • 38
  • 71
0

I have done it with NJsonSchema with below code

var json = JsonSchema.FromJsonAsync(schemafile); 
var jsonSchema = json.Result;
JToken jsonValue = JToken.Parse(value);
var result = jsonSchema.Validate(jsonValue);