json schema to validate datetime is after unix epoch or not

504 views
Skip to first unread message

sampa...@gmail.com

unread,
Dec 4, 2015, 1:13:45 PM12/4/15
to JSON Schema

Hi All


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


Thank you

Sampath

Joe McIntyre

unread,
Dec 4, 2015, 3:58:35 PM12/4/15
to JSON Schema, sampa...@gmail.com
Sampath,

A regular expression can be added to the validation as shown below,

{
  "type" : "array",
   "items" : { 
     "type": "string",
     "format": "date-time",
     "pattern": "^(19[7-9]|2[0-9][0-9])[0-9]"
  }  
}

This is generate an error if the date is before the epoch date.
The regular expression checks the first four characters in the string for >= 1970.
Reply all
Reply to author
Forward
0 new messages