1

I have been looking into both JSON.NET Schema and NJsonSchema. Both don't seem to have any property / method that identifies if a JSON Schema is a valid one and in accordance with draft v4.

Is it that only an exception will identify if a schema is valid, and even if it's valid, how will I check that it's draft v4 compatible?

Marcos Dimitrio
  • 6,651
  • 5
  • 38
  • 62
Sana.91
  • 1,999
  • 4
  • 33
  • 52

1 Answers1

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);
James Newton-King
  • 48,174
  • 24
  • 109
  • 130
  • Yes i did, JSchema schema = JSchema.Parse(schemaJson); will tell me that schema itself is invalid only if an exception will occur , is'nt there another way to determine that schema itself ontains errors ? – Sana.91 Oct 16 '17 at 04:35
  • I see. What you can do is validate the JSON you want to load as a schema with a schema that describes the v4 draft. I updated my answer. – James Newton-King Oct 16 '17 at 07:25