writeOnly : Boolean

writeOnly

Boolean

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