JSON模式:使用另一个对象中定义的属性值
我在JSON模式中有两个属性:“ a”:{“ type”:“对象”,“属性”:{“ x”:{“ type”:“ boolean”}}}}}
“ b”:{“类型”:“对象”,“属性”:{...}}
在b
的逻辑中,我需要使用x 要设置
b
属性值和“必需”:[...]
。
如何在b
中使用x
的值?
I have two properties in JSON Schema:"A": {"type": "object", "properties":{ "X":{"type":"boolean"}}}
"B": {"type": "object", "properties":{...}}
In the logic of B
I need to use value of X
to set B
property values and "required":[...]
.
How do I use value of X
within the B
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要在定义包含这两个属性的对象的模式级别上声明规则。然后,您可以使用
depententsChemas
,依赖性重新定制
,或如果
/然后
/else
else 关键字来定义诸如“ if< gt;在属性A中的某物,然后<在属性b中”的关键字。。
条件 “”。
You need to declare a rule at the schema level that defines the object that contains these two properties. You can then use the
dependentSchemas
,dependentRequired
, orif
/then
/else
keywords to define rules like "if <something> in property A, then <something> in property B".https://json-schema.org/understanding-json-schema/reference/conditionals.html
For example:
This is saying "if property A exists, and has a subproperty X which is true, then there must be a property Y under B which is the string "/A/X is true"".
谈到JSON模式的标准规范,您不能在其他位置“使用” JSON实例中的值以进行验证,例如,您要拿一个值并填写
必需的与之关键字。
但是,您可以使用
if-then-else
来定义条件,该使用值来决定验证流中此时应随后应用哪些其他模式。依赖性Chemas
和依赖性重新定价
关键字集中在属性的存在上。更多详细信息可用在这里。
Speaking about the standard specification of JSON Schema in general, you can't "use" values from the JSON instance at some other place for validation in the meaning that, for example, you take a value and fill a
required
keyword with it.However, you can define conditions using
if-then-else
that use values to decide what other schemas should be applied subsequently at this point in the validation flow.The
dependentSchemas
anddependentRequired
keywords are focused on the presence of properties.More details are available here.