readOnly : Boolean

readOnly

Boolean

This 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 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 Hint: Use the jsonschema validate command to collect annotations from the command-line
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 does not affect validation, but the evaluator will collect its value as an annotation.

Examples

A schema that statically marks the id optional object property as read only Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "properties": {
    "id": { "type": "integer", "readOnly": true },
    "value": { "type": "integer" }
  }
}
Valid An object value that defines the read only property is valid but an annotation is emitted Instance
{ "id": 1234, "value": 5 }
Annotations
{ "keyword": "/properties/id/readOnly", "instance": "/id", "value": true }
Valid An object value that does not define the read only property is valid and no annotation is emitted Instance
{ "value": 5 }
Invalid An object value that does not match the schema is invalid and no annotations are emitted Instance
{ "id": 1234, "value": null }
A schema that dynamically marks the id optional object property as read only based on the presence of the data property Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "properties": {
    "id": { "type": "integer" },
    "value": { "type": "integer" }
  },
  "dependentSchemas": {
    "value": {
      "properties": { "id": { "readOnly": true } }
    }
  }
}
Valid An object value that defines both properties is valid but an annotation is emitted Instance
{ "id": 1234, "value": 5 }
Annotations
{ "keyword": "/dependentSchemas/value/properties/id/readOnly", "instance": "/id", "value": true }
Valid An object value that only defines the value property is valid and no annotation is emitted Instance
{ "value": 5 }
Valid An object value that only defines the id property is valid and no annotation is emitted Instance
{ "id": 1234 }
Invalid An object value that does not match the schema is invalid and no annotations are emitted Instance
{ "value": null }