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
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 with 'readOnly' keyword Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "readOnly": true,
  "type": "number"
}
Valid An instance with a numeric value is valid Instance
45
Annotations
{ "keyword": "/readOnly", "instance": "", "value": true }
Schema with logical operators Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "if": {
    "properties": {
      "immutable": { "const": true }
    }
  },
  "then": {
    "readOnly": true
  },
  "else": {
    "readOnly": false
  }
}
Valid Instance
{ "immutable": false }
Annotations
{ "keyword": "/else/readOnly", "instance": "", "value": false }
Valid Instance
{ "immutable": true }
Annotations
{ "keyword": "/then/readOnly", "instance": "", "value": true }
Schema with multiple annotations for the same instance Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "readOnly": true,
  "$ref": "#/$defs/name",
  "$defs": {
    "name": {
      "readOnly": true,
      "type": "string"
    }
  }
}
Valid Instance
"John Doe"
Annotations
{ "keyword": "/readOnly", "instance": "", "value": true }
{ "keyword": "/$ref/readOnly", "instance": "", "value": true }