Deprecated, readOnly, and writeOnly

In this lesson, we will learn about the deprecated, readOnly, and writeOnly keywords in JSON Schema.

Deprecated

The deprecated keyword is a boolean that indicates that the instance value the keyword applies to should not be used and may be removed in the future.

1{
2  "type": "string",
3  "deprecated": true
4}

In the above example, the schema is marked as deprecated. This means that the schema should not be used.

readOnly and writeOnly

The boolean keywords readOnly and writeOnly are typically used in an API context.

readOnly indicates that a value should not be modified. It could be used to indicate that a PUT request that changes a value would result in a 400 Bad Request response.

writeOnly indicates that a value may be set, but will remain hidden. In could be used to indicate you can set a value with a PUT request, but it would not be included when retrieving that record with a GET request.

1{
2  "type": "object",
3  "properties": {
4    "name": {
5      "type": "string",
6      "readOnly": true
7    },
8    "age": {
9      "type": "number",
10      "writeOnly": true
11    }
12  }
13}

Here, the name property is marked as readOnly, and the age property is marked as writeOnly.

Task

1{
2  "name":{
3    "firstName":"John",
4    "lastName":"Doe"
5  },
6  "age":25
7}
8

You are given schema of the above JSON object in side editor.

  • Add deprecated keyword to the schema.
  • Add readOnly in the schema to the name property
  • Add writeOnly to the age property.

You can use any value for these keywords.

Loading...
Output
Please click the button or use
Shift+Enter
to view the output