I am new to json , I want to write a json schema which accepts array of time stamps in ISO8061 standard and make sure that the time is after unix epoch i.e 1 January 1970 00:00:00
the date-time in json-schema is making sure that time is ISO8061 standard but it i could not able add constraint that the time should be after unix epoch i.e 1 January 1970 00:00:00
my json shema :
{ "$schema": "http://json-schema.org/draft-04/schema#",
"type" : "array", // array of time stamps
"items" : {
"type": "string",
"format": "date-time"
}
}
json data
["1954-12-11T00:00:00Z"]
Could you please let us know is there any we can a constrain on time filed at schema level that date-time provided should be after unix epoch i.e 1 January 1970 00:00:00
You can use the JSON schema
date-time
format, together with AJV (Another JSON schema validator) and itsformatMinimum
validator you can achieve what you want.A minimum working example that you can run e.g. on this website https://npm.runkit.com/ajv would be the following:
The first test fails because the test date is in 1954, so before the hard-coded minimum date of 1970-01-01. The second test is valid since the date from today (2018-11-30) is after 1970.