JSON 若干约定

JSON 是普遍使用的数据交换格式(The JSON Data Interchange Standard)。

JSON (JavaScript Object Notation)

JSON is a lightweight data-interchange format.

object&array

value

value

A value can be a string in double quotes, or a number, or true or false or null, or an object or an array. These structures can be nested.

  • null
  • boolean
    A "true" or "false" value.
  • object
    An object is an unordered set of name/value pairs.
  • array
    An array is an ordered collection of values. An array begins with [ (left bracket) and ends with ] (right bracket). Values are separated by , (comma).
  • number
    An arbitrary-precision, base-10 decimal number value.
    "integer" matches any number with a zero fractional part.
  • string
    a sequence of zero or more Unicode characters. Strings are delimited with double-quotation marks and support a backslash escaping syntax.

JSON Schema

  • describes your existing data format.
  • clear, human- and machine-readable documentation.
  • complete structural validation, useful for:
    1)automated testing.
    2)validating client-submitted data.

JSON Schema Validation

  • JSON Schema Validation: A Vocabulary for Structural Validation of JSON.
  • Latest JSON Schema Validation
    JSON Schema Validation defines the validation keywords of JSON Schema.
  • Validation Keywords
    比如:required、properties 就是 Validation Keywords for Objects.
  • JSON Schema Example
{
  "$schema": "http://json-schema.org/schema#",
  "title": "Product",
  "type": "object",
  "required": ["id", "name", "price"],
  "properties": {
    "id": {
      "type": "number",
      "description": "Product identifier"
    },
    "name": {
      "type": "string",
      "description": "Name of the product"
    },
    "price": {
      "type": "number",
      "minimum": 0
    },
    "tags": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "stock": {
      "type": "object",
      "properties": {
        "warehouse": {
          "type": "number"
        },
        "retail": {
          "type": "number"
        }
      }
    }
  }
}

JSON Editor Online

在线查看 json 格式文件。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,993评论 19 139
  • =========================================================...
    lavor阅读 3,508评论 0 5
  • "谢谢兄弟姐妹们,给我转转,出售2000多吨土豆,电话15049637866看到的一定帮!不给转开春以后有...
    YuZhiH阅读 401评论 2 2
  • 太经典的神作只能闭嘴膜拜,太经典的烂片懒得吐槽,只有这种不完美的电影非常让人有诉说的冲动。所以首先要声明,这不是一...
    戒嗔阅读 1,179评论 8 5
  • 没有深夜痛哭的人,不足以谈人生,而我觉得, 我离可以谈人生的日子不远了。 开始找工作了,也开始一段自己决定的路了,...
    Lasia阅读 305评论 0 2