标签: jsonschema

从JSON数据生成JSON模式的工具

我们有这个json架构草案.我想得到我的JSON数据样本并为JSON模式生成一个框架,我可以手动返工,添加描述,必需等内容,这些内容不能从具体示例中获取.

例如,从我的输入example.json:

{
    "foo": "lorem", 
    "bar": "ipsum"
}
Run Code Online (Sandbox Code Playgroud)

我会运行我的json_schema_g​​enerator工具,并得到:

{ "foo": {
    "type" : "string",
    "required" : true,
    "description" : "unknown"
  },
  "bar": {
    "type" : "string",
    "required" : true,
    "description" : "unknown"
  }
}
Run Code Online (Sandbox Code Playgroud)

此示例已手动编码,因此可能存在错误.是否有任何工具可以帮助我转换JSON - > JSON模式?

reflection validation json jsonschema

165
推荐指数
8
解决办法
20万
查看次数

有条件地需要jsonSchema属性

在jsonSchema中,您可以使用"required"属性指示已定义的字段是否为必填字段:

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "type": "object",
    "properties": {
        "header": {
            "type": "object",
            "properties": {
                "messageName": {
                    "type": "string"
                },
                "messageVersion": {
                    "type": "string"
                }
            },
            "required": [
                "messageName",
                "messageVersion"
            ]
        }
    },
    "required": [
        "header"
    ]
}
Run Code Online (Sandbox Code Playgroud)

在某些情况下,我希望messageVersion字段不是必需的.有没有办法让这个领域的强制性有条件?

jsonschema

79
推荐指数
2
解决办法
3万
查看次数

Json Schema文件扩展名

是否有json模式文件扩展名的命名约定?XML有.xsd(XML Schema Definition),json模式文件应该有什么,.jsd(JSON模式定义)?

json jsonschema

75
推荐指数
3
解决办法
2万
查看次数

从XML模式(XSD)生成Json模式

有人知道如何从现有的XML模式(XSD文件)生成JSON模式吗?有没有可用的工具?

xml json xsd transform jsonschema

71
推荐指数
4
解决办法
10万
查看次数

如何从Swagger API声明生成JSON-Schema

我使用Swagger v 1.2获得服务的Swagger API声明

我对Swagger的原始感觉是,它非常接近JSON Schema(草案3和最近草案4),并且为请求和响应对象生成JSON Schema相对容易.

然而,虽然Swagger的一部分重用了JSON Schema结构,但事实证明,它只使用了功能的子集,并且它还在模型中引入了它自己的继承(使用subTypesdiscriminator).

问题:是否有任何现有项目或代码片段可以从Swagger API声明生成可用的JSON模式

最佳JSON Schema Draft 4并使用Python(但我很乐意找到任何东西).

jsonschema swagger

67
推荐指数
3
解决办法
6万
查看次数

仅允许在JSON模式中声明的属性

我正在使用json-schema并且只想允许在此文件中声明的属性通过验证.例如,如果用户在其json对象中传递"name"属性,则该模式将失败,因为此处未将"name"列为属性.

是否有一些类似于"必需"的功能只允许列出的属性通过?

{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Accounting Resource - Add Item",
"type": "object",
"properties": {
    "itemNumber": {
        "type":"string",
        "minimum": 3
    },
    "title": {
        "type":"string",
        "minimum": 5
    },
    "description": {
        "type":"string",
        "minimum": 5
    }
},
"required": [
    "itemNumber",
    "title",
    "description"
]
}
Run Code Online (Sandbox Code Playgroud)

}

json jsonschema

62
推荐指数
3
解决办法
2万
查看次数

从JSON Schema生成C#类

我正在创建一个C#WCF Web服务,它以JSON格式返回大量数据.客户端是一个iPad应用程序,目前正在由另一个团队开发,所以我正在研究规范,没有示例数据.
目前,JSON字符串是由.net框架创建的,我的Web服务返回一个C#对象,其中包含然后使用DataContracts由框架序列化的所有信息.

我的问题是通信规范只包含JSON Schema文件(基于http://json-schema.org/).为了便于开发,我想在C#中生成相应的类,但由于文件包含大量信息,而且有十几个文件,我真的不想手动创建这些类.

所以我正在寻找一种工具,可以让我:

  • 从JSON模式生成C#类.
  • 将JSON模式转换为XSD文件.然后创建类很容易,因为有很多工具可以从XSD生成类.

我找到了许多工具来验证JSON模式的JSON字符串,或者从JSON字符串生成类,但似乎没有任何帮助我的东西.
JSON.NET,但它似乎是一个库,而不是一个工具,我没有找到任何有关使用它生成类的信息.

所以,如果有人知道一个工具或者有关于如何生成这些类的想法(我尝试了一个用Java创建类但我无法使其工作的工具).

.net wcf json jsonschema

61
推荐指数
6
解决办法
5万
查看次数

JSON模式:"allof"带有"additionalProperties"

假设我们有模式跟随模式(来自这里的教程):

{
  "$schema": "http://json-schema.org/draft-04/schema#",

  "definitions": {
    "address": {
      "type": "object",
      "properties": {
        "street_address": { "type": "string" },
        "city":           { "type": "string" },
        "state":          { "type": "string" }
      },
      "required": ["street_address", "city", "state"]
    }
  },

  "type": "object",

  "properties": {
    "billing_address": { "$ref": "#/definitions/address" },
    "shipping_address": {
      "allOf": [
        { "$ref": "#/definitions/address" },
        { "properties":
          { "type": { "enum": [ "residential", "business" ] } },
          "required": ["type"]
        }
      ]
    } 

  }
}
Run Code Online (Sandbox Code Playgroud)

这是有效的实例:

{
      "shipping_address": {
        "street_address": "1600 Pennsylvania Avenue …
Run Code Online (Sandbox Code Playgroud)

javascript json jsonschema

54
推荐指数
4
解决办法
2万
查看次数

在JSON模式中定义枚举数组的正确方法

我想用JSON模式数组来描述,该数组应包含零个或多个预定义值.为简单起见,让我们这些可能的值:one,twothree.

正确的数组(应该通过验证):

[]
["one", "one"]
["one", "three"]
Run Code Online (Sandbox Code Playgroud)

不正确:

["four"]
Run Code Online (Sandbox Code Playgroud)

现在,我知道"enum"应该使用该属性,但我找不到相关信息放在哪里.

选项A(下"items"):

{
    "type": "array",
    "items": {
        "type": "string",
        "enum": ["one", "two", "three"]
    }
}
Run Code Online (Sandbox Code Playgroud)

选项B:

{
    "type": "array",
    "items": {
        "type": "string"
    },
    "enum": ["one", "two", "three"]
}
Run Code Online (Sandbox Code Playgroud)

arrays enums json jsonschema

49
推荐指数
2
解决办法
4万
查看次数

如何在json模式中定义数组的最小大小

我想制作一个json文件的模式.它是一组产品.

json架构类似如下:

{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Product set",
"type": "array",
"items": {
    "title": "Product",
    "type": "object",
    "properties": {
        "id": {
            "description": "The unique identifier for a product",
            "type": "number"
        },
        "name": {
            "type": "string"
        },
        "price": {
            "type": "number",
            "minimum": 0,
            "exclusiveMinimum": true
        },
        "tags": {
            "type": "array",
            "items": {
                "type": "string"
            },
            "minItems": 1,
            "uniqueItems": true
        },
        "dimensions": {
            "type": "object",
            "properties": {
                "length": {"type": "number"},
                "width": {"type": "number"},
                "height": {"type": "number"}
            },
            "required": ["length", "width", "height"]
        },
        "warehouseLocation": …
Run Code Online (Sandbox Code Playgroud)

arrays json jsonschema

45
推荐指数
3
解决办法
2万
查看次数

标签 统计

jsonschema ×10

json ×8

arrays ×2

.net ×1

enums ×1

javascript ×1

reflection ×1

swagger ×1

transform ×1

validation ×1

wcf ×1

xml ×1

xsd ×1