JSON中 $ref 的用法

本文介绍了JSON Schema中$ref关键字的使用方法,该关键字用于引用和重用schema定义。通过实例解析了$ref如何实现对当前schema自身的引用,以及如何指向文档内其他位置的schema定义。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

JSON中 $ref 的用法

It is a keyword you can use to refer and reuse schemas.
是用来引用,重复使用schema 。

Schema:
{"type": "object",
"title": "A Non-empty linked list",
"required": ["value", "next"],
"properties": {
"value":{"type": "integer"},
        "next": {"oneOf":[{"type": "null"},
					     {"$ref": "#"}]}}}

#是指scheme本身。

有效的输入可以是
{“value”: 1, “next”: {“value”:2, “next”: null}}
可以看出来,next 在one of 中如果选择的是 {"$ref": “#”}]}}}
那么就是指的是schema,所以{“value”: 1, “next”: {“value”:2, “next”: null}} 是正确的。

==========================
{ “$ref”: “#/definitions/address” }
$ref是URI引用,#符号后的部分(“片段”或“命名锚点”)采用称为JSON指针的格式。
$ref值以井号(#)开头。之后,以斜杠分隔的项目遍历文档中对象中的键

收藏:
https://www.postgresql.org/docs/12/functions-json.html

https://json-schema.org/understanding-json-schema/structuring.html

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值