json-schema pasa la validación si se pasa una matriz en lugar de un objeto

This is my schema which manage profile in our application :

var ProfileJsonSchema = {
  properties: {
    Profiles: {
      optional: false,
      items: {
        optional: false,
        properties: {
          Email: {type: String},
          FirstName: {type: String},
          Zip: {type: String},
          City: {type: String}

y mis datos


and the code to test

validation = Validate([{}], ProfileJsonSchema);     
if (!validation.valid) {
// do something...

Well the validation is ok. Why ? Is there a solution to handle this type of error?

preguntado el 01 de febrero de 12 a las 14:02

What JSON Schema Implementation did you choose? Can you provide a JSFiddle example? jsfiddle.net -

I have done some tests with the CommonJs version and the latest kriszyp version (github.com/kriszyp/json-schema). I'm not good enough to put a standalone script on jsfiddle :( -

2 Respuestas

There's maybe a typo here:

validation = Validate([{}], , ProfileJsonSchema); 

3 parameters instead of 2?

Respondido 07 Feb 12, 16:02

To answer this a decade late, the json schema type assertion in missing. In the absence of this, any type is valid. The properties assertion may seem like it would only allow objects, but actually, it only asserts that if a property Profiles exists then it must satisfy the declared subschema. Desde Profiles isn't even a required property, any object that does not have a Profiles property is also valid.

Respondido el 07 de junio de 21 a las 17:06

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.