I\'m trying a poc. Is possible optimize json.net schema with JSchemaValidatingReader to deserialize in object in same read of stream?
In otherworld
stri
Yes, JSchemaValidatingReader is a subclass of JsonReader, so you can use it to deserialize by passing it to JsonSerializer.Deserialize(JsonReader):
using (var s = File.OpenText(@"c:\bigdata.json"))
using (var baseReader = new JsonTextReader(s))
using (var reader = new JSchemaValidatingReader(baseReader))
{
reader.Schema = schema;
reader.ValidationEventHandler += (sender, args) => { Console.WriteLine(args.Message); };
root = JsonSerializer.CreateDefault().Deserialize<RootObject>(reader);
}
Demo fiddle here.
Related documentation: Validate JSON with JSchemaValidatingReader.