writeOnly : Boolean
writeOnly
BooleanThis keyword indicates that the value is never present when the instance is retrieved from the owning authority.
Value | This keyword must be set to a boolean value |
---|---|
Kind | Annotation |
Applies To | Any |
Dialect | 2020-12 |
Changed In | None |
Introduced In | Draft 7 |
Vocabulary | Meta Data |
Specification | https://json-schema.org/draft/2020-12/json-schema-validation.html#section-9.4 |
Metaschema | https://json-schema.org/draft/2020-12/meta/meta-data |
Official Tests | None |
Default |
false
|
Annotation | Boolean The boolean value set by this keyword |
Affected By | None |
Affects | None |
Also See |
the writeOnly
keyword is used to indicate that an instance value should be writable, but it won’t be included when the instance is retrieved from the owning authority. It’s important to note that this doesn’t imply the schema itself is writable; schemas must be treated as immutable. Instead, the keyword specifies instances where read/write operation semantics are use case specific.
writeOnly
does not affect data validation but serves as an informative annotation.
Examples
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"writeOnly": true,
"type": "number"
}
45
{ "keyword": "/writeOnly", "instance": "", "value": true }
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"if": {
"properties": {
"sensitive": { "const": true }
}
},
"then": {
"writeOnly": true
},
"else": {
"writeOnly": false
}
}
{ "sensitive": false }
{ "keyword": "/else/writeOnly", "instance": "", "value": false }
{ "sensitive": true }
{ "keyword": "/then/writeOnly", "instance": "", "value": true }
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"writeOnly": true,
"$ref": "#/$defs/name",
"$defs": {
"name": {
"writeOnly": true,
"type": "string"
}
}
}
"John Doe"
{ "keyword": "/writeOnly", "instance": "", "value": true }
{ "keyword": "/$ref/writeOnly", "instance": "", "value": true }