what is a schema?作用与位置

本文介绍了JSON作为数据交换格式的基本结构,包括对象、数组、数值、字符串等类型,并通过示例展示了其灵活性。然而,这种灵活性可能导致数据表示不一致,为此引入了JSON Schema来定义和验证数据结构。JSON Schema是一种使用JSON编写的规范,用于描述和验证其他JSON数据的结构。通过JSON Schema,可以确保数据记录如人员信息的格式正确,例如在姓名、生日和地址字段上的约定。文章还提到,复杂的验证通常涉及结构级和语义级两阶段验证。
部署运行你感兴趣的模型镜像

if you have ever used XML Schema, RelaxNG or ASN. you probably already know what a schema is and you can happly skip along to the next section. if all that sounds like gobbledygook to you, you have come to right place. To define what JSON Schema is, we should probably fist define what JSON is.
JSON stands for “javaScript Object Notation”, a simple data interchange format. It began as a nataion for the world wide web. Since JavaScript exists in most web browers, and JSON is base on JavaScript, it is very easy to support there. However, it has proven useful enough and simple enough that it is now used in many other contexts that does not invole web surfing.
At its heart, JSON is built on the following data structures:

  • object: {“key1”:“value1”, “key2”:“value2”}
  • array: [“fist”, “second”, “third”]
  • number: 42
  • string: “This is a string”
  • boolean: true false
  • null: null
    these types have analogs in most programming languages, though they may go by different names.
    With these simple data types, all kinds of structured, With that great fiexibillty comes great responsibillty, however, as the same concept could be represented im myriad ways. For example, you could imagine prepresenting imformation about a person in JSON indifferent ways:
{
	"name":"Geoege Washington",
	"brithday":"February 22 , 1732",
	"address":"mount Vernon, Virginia, United States"
}

{
	"first_name":"George",
	"last_name":"Washington",
	"birthday":"1732-02-22",
	"address"{
		"street_address":"3200 Mount Vernon Memorial Highway",
		"city":"Mount Vernon",
		"state":"Virginia",
		"country":"United States"
	}
}

Both representations are equally valid, though one is clearly more formal than the other. The design of a record will largely depend on its intended use within the application, so there is no right or wrong answer here. However, when an application says “give me a JSON record for a person”, it’s important to know exactly how that record should be organized . For example, we need to know what fields are expected, and how the values are represented. That is where JSON Schema comes in. The following JSON Schema fragment describes how the second example above is structured. Do not very too much about the details for now. They are explained in subsequent chapters.

{
	"type":"object",
	"properties":{
		"first_name":{"type":"string"},
		"last_name":{"type":"string"},
		"brithday":{"type":"string", "format":"date"},
		"address":{
			"type":"object",
			"properties":{
				"street_address":{"type":"string"},
				"city":{"type":"string"},
				"state":{"type":"string"},
				"country":{"type":"string"}
			}
		}	
    }
}

By “validating” the first example against this schema, you can see that it fails;
However, the second example passes;

You may have noticed that the JSON schema itself is written in JSON. It is data itself, not a computer program. It is just a declarative format for “describing the structure of other data”. This is both its strength and its weakness(which it shares with other similar schema languages).it is easy to concisely describe the surface structure of data, and automate validating data against it. However, since a JSON Schema can not contain arbitrary code, there are certain constraints on the relationships between data elements that can not be expressed.**Any “validation tool” for a sufficiently complex data format, therefore, will likely have two phases of validation: one at the schema(or structural) level, and one at the semantic level.**The latter check will likely need to be implemented using a more general-purpose programming language.

您可能感兴趣的与本文相关的镜像

ACE-Step

ACE-Step

音乐合成
ACE-Step

ACE-Step是由中国团队阶跃星辰(StepFun)与ACE Studio联手打造的开源音乐生成模型。 它拥有3.5B参数量,支持快速高质量生成、强可控性和易于拓展的特点。 最厉害的是,它可以生成多种语言的歌曲,包括但不限于中文、英文、日文等19种语言

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值