简体   繁体   中英

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

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?

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM