Generating JSON schema from C# class

Ravi Gupta picture Ravi Gupta · Apr 3, 2013 · Viewed 33.3k times · Source

Is there any way to programmatically generate a JSON schema from a C# class?

Something which we can do manually using http://www.jsonschema.net/

Answer

Rico Suter picture Rico Suter · Oct 12, 2015

Another option which supports generating JSON Schema v4 is NJsonSchema:

var schema = JsonSchema.FromType<Person>();
var schemaJson = schema.ToJson();

The library can be installed via NuGet.

Update for NJsonSchema v9.4.3+:

using NJsonSchema;

var schema = await JsonSchema.FromTypeAsync<Person>();
var schemaJson = schema.ToJson();