How to validate JSON Schema according to Draft v4 using JSON.NET Schema or NJSONSchema?

让人想犯罪 __ 提交于 2019-12-11 15:03:46

问题


I have been looking into both JSON.NET Schema and NJsonSchema ... Both dont seem to have any propert / method that identifies if JSON Schema is a valid JSON Schema and in accordance with draft v4 Compatible.

Is it that only an exception that will identify if a schema is valid, and even if its vaid, how will i check that its draft v4 Comatible?


回答1:


You can use a JSON schema that describes JSON schema and use that to validate the JSON.

You can find a copy here - http://www.jsonschemavalidator.net/api/jsonschemastore/schema?schemaUrl=schema-draft-v4

string draftV4SchemaJson = @"{}"; // replace with content from http://www.jsonschemavalidator.net/api/jsonschemastore/schema?schemaUrl=schema-draft-v4

JSchema draftV4Schema = JSchema.Parse(draftV4SchemaJson);

JObject yourSchemaJson = JObject.Parse(@"{}"); // your schema

bool valid = yourSchemaJson.IsValid(draftV4Schema);


来源:https://stackoverflow.com/questions/46756918/how-to-validate-json-schema-according-to-draft-v4-using-json-net-schema-or-njson

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!