JSON SCHEMA USAGE

Jul 1, 2010 at 5:06 PM

Hi

I have designed a validation schema but found that some of the constraints don't seem to work, e.g. the min/MaxItems for an array or required option.  This is the schema & code:

 

 

 

 

 

 

 

<font size="2">

 

</font>Dim s As String

= FinanceValidators.personalDetailsSchema<font size="2">

 

</font>

Dim

schema = JsonSchema.Parse(s)<font size="2">

 

</font>

Dim person As

Newtonsoft.Json.Linq.JToken = Newtonsoft.Json.JsonConvert.DeserializeObject(perDetails)<font size="2">

 

</font>

Try

Newtonsoft.Json.Schema.Extensions.Validate(person, schema)

<font size="2">

 

</font>
Catch exception As

Newtonsoft.Json.Schema.JsonSchemaException

s = exception.Message.ToString

<font size="2">

 

</font>

Return

s.Split(vbCrLf)<font size="2">

 

</font>

End

Try

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

<font size="2">

 

</font>"{"

& _<font size="2">

 

</font>

"'description':'Personal Details JSON ARRAY SCHEMA',"

& _<font size="2">

 

</font>

"'type':'array',"

& _<font size="2">

 

</font>

"'items':{"

& _<font size="2">

 

</font>

"'title':'An Applicant details',"

& _<font size="2">

 

</font>

"'type':'object',"

& _<font size="2">

 

</font>

"'properties':{"

& _<font size="2">

 

</font>

"'Title':{'type':'string','enum':['MR','Mr','MRS','Mrs','MISS','Miss','MS','Ms','DR','Dr','REV','Rev']},"

& _<font size="2">

 

</font>

"'Forename':{'type':'string','maxLength':15},"

& _<font size="2">

 

</font>

"'Surname':{'type':'string','maxLength':19},"

& _<font size="2">

 

</font>

"'MiddleName':{'type':'string','maxLength':15,'optional':true},"

& _<font size="2">

 

</font>

"'FormerSurname':{'type':'string','maxLength':30},"

& _<font size="2">

 

</font>

"'HadFormerSurname':{'type':'string','enum':['Y','N']},"

& _<font size="2">

 

</font>

"'DOB':{'type':'string','pattern':'(0[1-9]|[12][0-9]|3[01])[/](0[1-9]|1[012])[/]((175[7-9])|(17[6-9][0-9])|(1[8-9][0-9][0-9])|([2-9][0-9][0-9][0-9]))'},"

& _<font size="2">

 

</font>

"'HomeSTD':{'type':'string','pattern':'^[0-9]{5}$'},"

& _<font size="2">

 

</font>

"'HomePhone':{'type':'string','pattern':'^[0-9]{8}$'},"

& _<font size="2">

 

</font>

"'MobilePhone':{'type':'string','pattern':'(075|077|078|079)\\s?\\d{2}\\s?\\d{6}'},"

& _<font size="2">

 

</font>

"'LandLineIsHome':{'type':'string','enum':['Y','N']},"

& _<font size="2">

 

</font>

"'EmailAddress':{'type':'string','optional':true,'pattern':'^([\\w-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([\\w-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$'},"

& _<font size="2">

 

</font>

"'ResidentialStatus':{'type':'string','enum':['H','L','R','T']},"

& _<font size="2">

 

</font>

"'MortgageHolder':{'type':'string','enum':['Y','N']},"

& _<font size="2">

 

"'YearsMortgageHeld':{'type':'string','maxLength':2},"

& _<font size="2">

 

</font>

"'NoDependants':{'type':'string','maxLength':1},"

& _<font size="2">

 

</font>

"'MaritalStatus':{'type':'string','enum':['Married','Single','Divorced','Widowed','Separated','Partners']},"

& _<font size="2">

 

</font>

"'Gender':{'type':'string','enum':['M','F']},"

& _<font size="2">

 

</font>

"'secAppForename':{'type':'string','maxLength':15,'optional':true},"

& _<font size="2">

 

</font>

"'secAppTitle':{'type':'string','enum':['MR','Mr','MRS','Mrs','MISS','Miss','MS','Ms','DR','Dr','REV','Rev'],'Requires':'secAppForename','optional':true},"

& _<font size="2">

 

</font>

"'secAppSurname':{'type':'string','maxLength':19,'optional':true},"

& _<font size="2">

 

</font>

"'secAppMiddleName':{'type':'string','maxLength':15,'optional':true}"

& _<font size="2">

 

</font>

"}}}"

</font>