0

I'm writing code for validation of json request for user creation method. Validator have to check whether the email field is equal to field confirmEmail. Request example:

{
     "firstName":"Homer",
     "lastName":"Simpson", 
     "email":"test1234@fox.com",
     "confirmEmail":"test1234@fox.com",
     ...
}

I'm using the tv4 schema validation lib. The goal is to write a schema to validate equality between email and confirmEmail fields.

Of course I can check the those fields in request directly but I'd use it as last resort in case schema validation will not work.

jruizaranguren
  • 12,679
  • 7
  • 55
  • 73
Vladimir
  • 12,753
  • 19
  • 62
  • 77
  • @luis espinal, jsonschema is a concrete standard. This question refers to jsonschema standard so it should be tagged that way. – jruizaranguren Dec 22 '14 at 21:40
  • Correct, it is an standard. But the question is about having succinct tags. So if we keep 'json' and 'jsonschema', then we should add 'schema' to make it uniform (it makes no sense to **NOT** have 'schema' if we have 'json' alongside 'jsonschema'. ). And if in doing so, we would get 'json' and 'schema', which would render 'jsonschema' redundant. In the same way people search for 'xml' and 'schema', most people search for 'json' + 'schema' as opposed to 'jsonschema' (unless they are searching for a specific software package or domain name.) – luis.espinal Dec 22 '14 at 21:50
  • Yes, I would substitute schema for jsonschema, having just json and jsonschema. Probably all posts related to json-schema excepting this one are tagged with json and jsonschema (http://stackoverflow.com/questions/tagged/jsonschema). It is not about succint tags but descriptive and defining tags. Search works nicely with json+schema, json-schema, jsonschema and [jsonschema] for all json-schema related questions. – jruizaranguren Dec 27 '14 at 12:23
  • http://meta.stackoverflow.com/questions/281219/json-and-jsonschema-tag-vs-json-and-schema-tags – jruizaranguren Dec 27 '14 at 17:10

3 Answers3

1

You can not test equality of values between properties with json-schema. Json-schema is used to validate json structure.

You can test that those fields exist and that they are correct emails through regex. You could even test that they belong to a set of predefined values in an enumeration. But nothing else.

jruizaranguren
  • 12,679
  • 7
  • 55
  • 73
0

In my project, I am using jpv module

const jpv = require('jpv');

const pattern = {
     "firstName" : /.+/,
     "email" : "[email]",
     ...
};

const isVaild =  jpv.validate(obj, pattern)
Manvel
  • 750
  • 7
  • 10
-1
jpv.validate(data, messageSchema))