Generating JSON schema from C# class

前端 未结 3 715
梦毁少年i
梦毁少年i 2020-12-28 14:34

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/

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-28 14:52

    Another option which supports generating JSON Schema v4 is NJsonSchema:

    var schema = JsonSchema.FromType();
    var schemaJson = schema.ToJson();
    

    The library can be installed via NuGet.

    Update for NJsonSchema v9.4.3+:

    using NJsonSchema;
    
    var schema = await JsonSchema.FromTypeAsync();
    var schemaJson = schema.ToJson();
    

提交回复
热议问题