Tag: jsonschema

如何使用JSON.net引用外部文件?

这是我在JSON.net尝试读取我的JSON模式时遇到的错误( return JsonSchema.Read(new JsonTextReader(reader)); ): 2014-07-15 15:33:42.7011 [Fatal] Newtonsoft.Json.JsonException: Could not resolve schema reference ‘data-result.json’. at Newtonsoft.Json.Schema.JsonSchemaBuilder.ResolveReferences(JsonSchema schema) in c:\Development\Releases\Json\Work ing\Newtonsoft.Json\Src\Newtonsoft.Json\Schema\JsonSchemaBuilder.cs:line 139 at Newtonsoft.Json.Schema.JsonSchemaBuilder.ResolveReferences(JsonSchema schema) in c:\Development\Releases\Json\Work ing\Newtonsoft.Json\Src\Newtonsoft.Json\Schema\JsonSchemaBuilder.cs:line 179 at Newtonsoft.Json.Schema.JsonSchemaBuilder.Read(JsonReader reader) in c:\Development\Releases\Json\Working\Newtonsof t.Json\Src\Newtonsoft.Json\Schema\JsonSchemaBuilder.cs:line 85 at Newtonsoft.Json.Schema.JsonSchema.Read(JsonReader reader, JsonSchemaResolver resolver) in c:\Development\Releases\ Json\Working\Newtonsoft.Json\Src\Newtonsoft.Json\Schema\JsonSchema.cs:line 280 at Newtonsoft.Json.Schema.JsonSchema.Read(JsonReader reader) in c:\Development\Releases\Json\Working\Newtonsoft.Json\ Src\Newtonsoft.Json\Schema\JsonSchema.cs:line 266 at ThinkBinary.SchemaToPoco.Core.JsonSchemaToCodeUnit.LoadSchema(String file) […]

使用json模式指定值可以是字符串或null

希望这对其他人来说并不明显,因为我发现http://json-schema.org/上的文档缺乏更精细的细节。 我正在获取一个json块,其中包含一些可以为null或字符串的属性。 如何在json模式(由json.NET的JsonSchema.Parse方法解析)中指定值可以是null类型还是类型字符串? 有什么简单的我缺少像为类型提供数组? 例如; “member_region”: { “type”: [ “string”, null ] } // this throws an exception 另外,有没有人比json-schema.org有更好的json架构细节来源? 我在哪里可以找到更多的例子? 我不想阅读大的doc / spec来找到一些可以在10行示例中轻松演示的内容。

为ASP.Net Web API生成JSON模式

我正在寻找为WebAPI生成JSON Schema,包括来自XML注释的文档。 主要是因为我可以将其导入到我们的API文档中(使用apiary.io)我设法通过添加swagger(和swashbuckle)然后在每个服务上使用原始链接来获得解决方案 – 但理想情况下我会比较干净的东西,适用于所有api(这必须按服务/控制器完成),并没有这么多的依赖。 在我开始看看swagger是如何做这个并看看它是否可以被提取之前,如果有现成的方法可以做到这一点会很好吗?

使用JSON.NET生成具有额外属性的JSON模式

我正在使用JSON.NET从c#对象类生成JSON Schema。 但是我无法添加任何其他json架构属性,例如maxLength,pattern(用于validation电子邮件的正则表达式)等 下面是我的工作代码,我只能生成带有必需属性的json模式。 如果有人能发布一些关于如何为json模式添加额外属性的代码示例,那将是很棒的。 谢谢, 我的代码示例 public class Customer { [JsonProperty(Required = Required.Always)] public int CustomerID { get; set; } [JsonProperty(Required = Required.Always)] public string FirstName { get; set; } [JsonProperty(Required = Required.Always)] public string LastName { get; set; } [JsonProperty(Required = Required.Always)] public string Email { get; set; } [JsonProperty(Required = Required.AllowNull)] public […]

从C#类生成JSON模式

有没有办法以编程方式从C#类生成JSON模式? 我们可以使用http://www.jsonschema.net/手动完成的事情

在将JSON解析为JToken时如何将所有键更改为小写

我有一个JSON字符串,键有大写和小写字符: {“employees”:[ {“FIrstName”:”John”, “LASTname”:”Doe”}, {“FIRSTNAME”:”Anna”, “LaSTNaME”:”Smith”}, {“firstName”:”Peter”, “lastName”:”Jones”} ]} 我想将它转换为JToken对象,并将JToken所有键都JToken为小写。 所以JToken内部应该如下: {“employees”:[ {“firstname”:”John”, “lastname”:”Doe”}, {“firstname”:”Anna”, “lastname”:”Smith”}, {“firstname”:”Peter”, “lastname”:”Jones”} ]} 以前我用的是JToken json = JToken.Parse(jsonString); 转换,但我不知道如何使键小写。 有任何想法吗? 我需要这样做的原因是我的JsonSchemavalidation将不区分大小写。

针对JSON Schema C#validationJSON

有没有办法针对该结构的JSON模式validationJSON结构? 我已经查看并发现JSON.Netvalidation但这不符合我的要求。 JSON.net做: JsonSchema schema = JsonSchema.Parse(@”{ ‘type’: ‘object’, ‘properties’: { ‘name’: {‘type’:’string’}, ‘hobbies’: {‘type’: ‘array’} } }”); JObject person = JObject.Parse(@”{ ‘name’: ‘James’, ‘hobbies’: [‘.NET’, ‘LOLCATS’] }”); bool valid = person.IsValid(schema); // true 这证实为真。 JsonSchema schema = JsonSchema.Parse(@”{ ‘type’: ‘object’, ‘properties’: { ‘name’: {‘type’:’string’}, ‘hobbies’: {‘type’: ‘array’} } }”); JObject person = JObject.Parse(@”{ ‘surname’: […]