Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions draft-vasters-json-structure-cond-composition.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
---

title: "JSON Structure: Conditional Composition"
Expand Down Expand Up @@ -262,18 +262,21 @@
~~~json
{
"if": {
"type": "object",
"properties": {
"a": { "type": "string" }
},
"required": ["a"]
},
"then": {
"type": "object",
"properties": {
"b": { "type": "number" }
},
"required": ["b"]
},
"else": {
"type": "object",
"properties": {
"c": { "type": "boolean" }
},
Expand All @@ -282,6 +285,12 @@
}
~~~

As with every other schema object introduced by this document (`allOf`,
`anyOf`, `oneOf`, `not`), each of `if`, `then`, and `else` is itself a schema
object under JSON Structure Core {{JSTRUCT-CORE}} and MUST carry a `type`
keyword; `properties` alone does not establish that the node is constrained
to be an `object`.

Here, a JSON node evaluates to `true` if it is an object with a property `a` that is a string; then it must also have a property `b` that is a number:

~~~json
Expand Down Expand Up @@ -311,15 +320,15 @@
## Enabling the Extensions {#enabling-the-extensions}

The conditional composition extensions can be enabled in a schema or meta-schema
by adding the `JSONSchemaConditionalComposition` key to the `$uses` clause when
by adding the `JSONStructureConditionalComposition` key to the `$uses` clause when
referencing the extended meta-schema:

~~~ json
{
"$schema": "https://json-structure.org/meta/extended/v0/#",
"$id": "myschema",
"$uses": [
"JSONSchemaConditionalComposition"
"JSONStructureConditionalComposition"
],
"oneOf" : [
{ "type": "string" },
Expand Down
Loading