Newtonsoft
newtonsoft.com › jsonschema
Json.NET Schema - Newtonsoft
Generate JSON Schemas automatically from your existing .NET types.
Json.NET
Json.NET is a popular high-performance JSON framework for .NET
Pricing
Protect applications from unknown JSON. A complete JSON Schema framework for .NET.
Introduction
Json.NET is a popular high-performance JSON framework for .NET
Serializing and Deserializing JSON
The quickest method of converting between JSON text and a .NET object is using the T:Newtonsoft.Json.JsonSerializer. The JsonSerializer converts .NET objects into their JSON equivalent and back again by mapping the .
NuGet
nuget.org › packages › newtonsoft.json.schema
NuGet Gallery | Newtonsoft.Json.Schema 4.0.1
June 8, 2024 - JSchemaGenerator generator = new JSchemaGenerator(); JSchema schema = generator.Generate(typeof(Account)); // { // "type": "object", // "properties": { // "email": { "type": "string", "format": "email" } // }, // "required": [ "email" ] // } public class Account { [EmailAddress] [JsonProperty("email", Required = Required.Always)] public string Email; }
Videos
GitHub
github.com › JamesNK › Newtonsoft.Json.Schema
GitHub - JamesNK/Newtonsoft.Json.Schema: Json.NET Schema is a powerful, complete and easy to use JSON Schema framework for .NET · GitHub
Json.NET Schema is a powerful, complete and easy to use JSON Schema framework for .NET - JamesNK/Newtonsoft.Json.Schema
Starred by 257 users
Forked by 114 users
Languages C# 98.4% | PowerShell 1.6%
Newtonsoft
newtonsoft.com › jsonschema › help › html › N_Newtonsoft_Json_Schema.htm
Newtonsoft.Json.Schema Namespace
The Newtonsoft.Json.Schema namespace provides classes that are used to implement JSON schema.
Newtonsoft
newtonsoft.com › json › help › html › JsonSchema.htm
Validating JSON with JSON Schema
JSON Schema is used to validate the structure and data types of a piece of JSON, similar to XML Schema for XML.
Newtonsoft
newtonsoft.com › jsonschema › help › html › T_Newtonsoft_Json_Schema_JSchema.htm
JSchema Class
An in-memory representation of a JSON Schema. ... Namespace: Newtonsoft.Json.Schema Assembly: Newtonsoft.Json.Schema (in Newtonsoft.Json.Schema.dll) Version: 3.0.6
Newtonsoft
newtonsoft.com › jsonschema › help › html › GenerateSchema.htm
Generate JSON Schema
JSchemaGenerator generator = new JSchemaGenerator(); JSchema schema = generator.Generate(typeof(Person)); // { // "type": "object", // "properties": { // "Name": { // "type": [ "string", "null" ] // }, // "Age": { "type": "integer" } // }, // "required": [ "Name", "Age" ] // }
Newtonsoft
newtonsoft.com › json › help › html › T_Newtonsoft_Json_Schema_JsonSchema.htm
JsonSchema Class
An in-memory representation of a JSON Schema. ... Namespace: Newtonsoft.Json.Schema Assembly: Newtonsoft.Json (in Newtonsoft.Json.dll) Version: 12.0.1+509643a8952ce731e0207710c429ad6e67dc43db
Newtonsoft
newtonsoft.com › jsonschema › help › html › GeneratingSchemas.htm
Generating Schemas
Schema generation is performed by the JSchemaGenerator object. It maps .NET objects, collections, properties, and their attributes to their JSON Schema equivalent.
GitHub
github.com › JamesNK › Newtonsoft.Json.Schema › releases
Releases · JamesNK/Newtonsoft.Json.Schema
Json.NET Schema is a powerful, complete and easy to use JSON Schema framework for .NET - JamesNK/Newtonsoft.Json.Schema
Author JamesNK
Newtonsoft
newtonsoft.com › jsonschema › help › html › CreateJsonSchemaWithReferences.htm
Create JSON Schema with references
JSchema addressSchema = new JSchema { Type = JSchemaType.Object, Properties = { { "street", new JSchema { Type = JSchemaType.String } }, { "city", new JSchema { Type = JSchemaType.String } }, { "country", new JSchema { Type = JSchemaType.String } }, { "postCode", new JSchema { Type = JSchemaType.Integer } } } }; JSchema deliverySchema = new JSchema { Type = JSchemaType.Object, Properties = { { "date", new JSchema { Type = JSchemaType.String, Format = "date-time" } }, { "fromAddress", addressSchema }, { "toAddress", addressSchema } }, ExtensionData = { ["references"] = new JObject { ["address"]
Newtonsoft
newtonsoft.com › json › help › html › CreateJsonSchemaManually.htm
Create JSON Schema manually
JsonSchema schema = new JsonSchema(); schema.Type = JsonSchemaType.Object; schema.Properties = new Dictionary<string, JsonSchema> { { "name", new JsonSchema { Type = JsonSchemaType.String } }, { "hobbies", new JsonSchema { Type = JsonSchemaType.Array, Items = new List<JsonSchema> { new JsonSchema { Type = JsonSchemaType.String } } } }, }; string schemaJson = schema.ToString(); Console.WriteLine(schemaJson); // { // "type": "object", // "properties": { // "name": { // "type": "string" // }, // "hobbies": { // "type": "array", // "items": { // "type": "string" // } // } // } // } JObject person = JObject.Parse(@"{ 'name': 'James', 'hobbies': ['.NET', 'Blogging', 'Reading', 'Xbox', 'LOLCATS'] }"); bool valid = person.IsValid(schema); Console.WriteLine(valid); // true
Top answer 1 of 3
22
I finally just created a new project and copied/pasted their example and I see my painfully obvious mistake that I've been fighting with.
I should be using:
JSchema
and not
JsonSchema
2 of 3
6
My problem got resolved when I added a new NuGet Package after searching for "JSON.net schema", which resulted in showing another Newtonsoft.Json.Schema Package in option:
Tools > Nuget Package Manager > Manage Nuget Packages for Solution

After doing this, change JSONSchema object to JSchema object. This will remove the obsolete message and compile the code properly as well.
after:
string schemaJson = @"{
'description': 'A person',
'type': 'object',
'properties':
{
'name': {'type':'string'},
'hobbies': {
'type': 'array',
'items': {'type':'string'}
}
}
}";
change:
JsonSchema schema = JsonSchema.Parse(schemaJson);
to
JSchema schema = JSchema.Parse(schemaJson);
Newtonsoft
newtonsoft.com › jsonschema › help › html › LoadingSchemas.htm
Loading Schemas
The simplest way to load a JSON Schema is from a string using Parse(String).
Newtonsoft
newtonsoft.com › jsonschema › help › html › T_Newtonsoft_Json_Schema_Generation_JSchemaGenerator.htm
JSchemaGenerator Class
Json.NET Schema Documentation · API Reference · Newtonsoft.Json.Schema.Generation · JSchemaGenerator Class · JSchemaGenerator Constructor · JSchemaGenerator Properties · JSchemaGenerator Methods · Generates a JSchema from a specified Type. Inheritance Hierarchy ·
Newtonsoft
newtonsoft.com › jsonschema › help › html › Introduction.htm
Introduction
Json.NET Schema is a powerful, complete, and easy-to-use JSON Schema framework for .NET.
Newtonsoft
newtonsoft.com › json › help › html › JsonSchemaParse.htm
Parse JSON Schema from JSON
string schemaJson = @"{ 'description': 'A person', 'type': 'object', 'properties': { 'name': {'type':'string'}, 'hobbies': { 'type': 'array', 'items': {'type':'string'} } } }"; JsonSchema schema = JsonSchema.Parse(schemaJson); Console.WriteLine(schema.Type); // Object foreach (var property in schema.Properties) { Console.WriteLine(property.Key + " - " + property.Value.Type); } // name - String // hobbies - Array
Newtonsoft
newtonsoft.com › jsonschema › help › html › T_Newtonsoft_Json_Schema_SchemaVersion.htm
SchemaVersion Enumeration
JSON Schema version. Namespace: Newtonsoft.Json.Schema Assembly: Newtonsoft.Json.Schema (in Newtonsoft.Json.Schema.dll) Version: 3.0.6 · Syntax · C# Copy · public enum SchemaVersion · Members · See Also · Newtonsoft.Json.Schema Namespace ·
JSON Schema Validator
jsonschemavalidator.net
JSON Schema Validator - Newtonsoft
public class JsonSchemaController : ControllerBase { [HttpPost] [Route("api/jsonschema/validate")] public ValidateResponse Validate(ValidateRequest request) { // Load schema JSchema schema = JSchema.Parse(request.Schema); JToken json = JToken.Parse(request.Json); // Validate json IList<ValidationError> errors; bool valid = json.IsValid(schema, out errors); // Return error messages and line info to the browser return new ValidateResponse { Valid = valid, Errors = errors }; } } public class ValidateRequest { public string Json { get; set; } public string Schema { get; set; } } public class ValidateResponse { public bool Valid { get; set; } public IList<ValidationError> Errors { get; set; } }
Newtonsoft
newtonsoft.com › json › help › html › Properties_T_Newtonsoft_Json_Schema_JsonSchema.htm
JsonSchema Properties
Newtonsoft.Json.Schema · JsonSchema Class · JsonSchema Properties · AdditionalItems Property · AdditionalProperties Property · AllowAdditionalItems Property · AllowAdditionalProperties Property · Default Property · Description Property · Disallow Property ·