readOnly : Boolean
readOnly
BooleanThis keyword indicates that the value of the instance is managed exclusively by the owning authority, and attempts by an application to modify the value of this property are expected to be ignored or rejected by that 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 readOnly
keyword is used to indicate that the value of a particular property is managed exclusively by the owning authority, and attempts by an application to modify the value of this property are expected to be ignored or rejected by that authority. It essentially means that the instance value should not be modified.
It’s important to note that this keyword 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.
readOnly
does not affect data validation but serves as an informative annotation.
Examples
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"readOnly": true,
"type": "number"
}
45
{ "keyword": "/readOnly", "instance": "", "value": true }
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"if": {
"properties": {
"immutable": { "const": true }
}
},
"then": {
"readOnly": true
},
"else": {
"readOnly": false
}
}
{ "immutable": false }
{ "keyword": "/else/readOnly", "instance": "", "value": false }
{ "immutable": true }
{ "keyword": "/then/readOnly", "instance": "", "value": true }
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"readOnly": true,
"$ref": "#/$defs/name",
"$defs": {
"name": {
"readOnly": true,
"type": "string"
}
}
}
"John Doe"
{ "keyword": "/readOnly", "instance": "", "value": true }
{ "keyword": "/$ref/readOnly", "instance": "", "value": true }