1. 程式人生 > 其它 >JSON中 $ref 的用法

JSON中 $ref 的用法

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