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 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 writeOnly keyword, when set to true, signifies that an instance value (such as a specific object property) can be modified or removed but not read, whatever that means in the context of the system. For example, form generators may rely on this keyword to mark the corresponding input as as a password field. This keyword provides metadata for documentation purposes and does not affect validation.

Examples

A schema that statically marks the password optional object property as write only Schema
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "properties": {
    "username": { "type": "string" },
    "password": { "type": "string", "writeOnly": true }
  }
}
Valid An object value that defines the write only property is valid Instance
{ "username": "jviotti", "password": "mysupersecretpassword" }
Valid An object value that does not define the write only property is valid Instance
{ "username": "jviotti" }
Invalid An object value that does not match the schema is invalid Instance
{ "password": null }
A schema that dynamically marks the password optional object property as write only based on the presence of the username property Schema
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "properties": {
    "username": { "type": "string" },
    "password": { "type": "string" }
  },
  "dependencies": {
    "username": {
      "properties": { "password": { "writeOnly": true } }
    }
  }
}
Valid An object value that defines both properties is valid Instance
{ "username": "jviotti", "password": "mysupersecretpassword" }
Valid An object value that only defines the username property is valid Instance
{ "username": "jviotti" }
Valid An object value that only defines the password property is valid Instance
{ "password": "mysupersecretpassword" }
Invalid An object value that does not match the schema is invalid Instance
{ "password": null }