Tony Goodchild
Tony Goodchild

Reputation: 355

Incrementing default value in JSON schema

I am building a JSON schema to be used within a JSON editor. Within one array will be a set of objects. Each of these objects will have a property "id" that should be a unique identifier .

{
    "type": "array",
    "items": {
        "type": "object",
        "properties": {
            "id": {
                "type": "integer"
            },
            "name": {
                "type": "string",
                "title": "Name"
            },
            "brief": {
                "type": "string",
                "title": "Brief description"
            }
        },
        "required": ["id", "name"]
    }
}

Is it possible to specify in the schema that the ID should either:

  1. increment from the last object ID, or
  2. be set to the current timestamp

Upvotes: 1

Views: 1275

Answers (1)

tom redfern
tom redfern

Reputation: 31770

No it's not possible. JSON schema is a simple convention for defining and validating the structure of JSON documents, and the typing of values. Validation of values is limited, and something as complex as an incrementing ID is beyond this remit.

You will have to program for this after deserialization, or via some kind of parser.

Upvotes: 1

Related Questions