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
Hint: Use the jsonschema metaschema and jsonschema lint commands to catch keywords set to invalid values
|
|---|---|
| Kind | Annotation |
| Applies To | Any |
| Base Dialect | Draft 7 |
| Changed In | None |
| Introduced In | Draft 7 |
| Vocabulary | Validation |
| Specification | https://json-schema.org/draft-07/draft-handrews-json-schema-validation-01#rfc.section.10.3 |
| Metaschema | http://json-schema.org/draft-07/schema# |
| Official Tests | None |
| Default |
false
|
| Annotation | None |
| Affected By | None |
| Affects | None |
| Also See |
|
The readOnly keyword, when set to true, signifies that an instance value
(such as a specific object property) cannot be modified or removed, whatever
that means in the context of the system. For example, form generators may rely
on this keyword to mark the corresponding input as read only. This keyword provides metadata for documentation purposes and does not affect validation.
Best Practice
Avoid setting this keyword to the default value false. If an instance value
is not considered to be read only, the best practice is to omit the use of this
keyword altogether.
Also avoid simultaneously setting this keyword and the writeOnly keyword to true for the same instance
location, resulting in ambiguous semantics.
Common Pitfall
Tooling makers must be careful when statically traversing schemas in search of occurrences of this keyword. It is possible for schemas to make use of this keyword behind conditional operators, references, or any other type of keyword that makes it hard or even impossible to correctly locate these values in all cases.
For example, an instance property might only be read only under certain
conditions determined by a dynamic operator like anyOf.
Examples
{
"$schema": "http://json-schema.org/draft-07/schema#",
"properties": {
"id": { "type": "integer", "readOnly": true },
"value": { "type": "integer" }
}
}{ "id": 1234, "value": 5 }{ "value": 5 }{ "id": 1234, "value": null }{
"$schema": "http://json-schema.org/draft-07/schema#",
"properties": {
"id": { "type": "integer" },
"value": { "type": "integer" }
},
"dependencies": {
"value": {
"properties": { "id": { "readOnly": true } }
}
}
}{ "id": 1234, "value": 5 }{ "value": 5 }{ "id": 1234 }{ "value": null }