Skip to content


Validation of 'null' type #12

NicolasPelletier opened this Issue · 2 comments

2 participants


First of all, thanks for a great package. It is the only one I could find for Node.js which seem to support 'format' properly.

After a while using another package where the 'format' was not supported ( I was new to JSON schema ) I am looking at using your package because it demonstrated ease of use, speed and also clear and easy to understand code.

However ( and I bet you saw that one coming ) I have schema written as thus:

    type: 'null',
    description: 'On success, nothing is returned.'

This is for an internal subroutine operation on our server where nothing needs to be returned directly. Unfortunately, valid-schema.js starts by validating that the schema is either of type 'object' or of type 'array'. This stops the createSchema() from accepting my schema.

I could easily change your code to make it work for me ( and I did fork it this afternoon to look into that ). But I would like to understand the reasoning of your implementation. I can't seem to find anything in the spec ( draft 3 ) which requires that a schema be forced to be an 'object' or an 'array'.

From the spec, I see the following:

 null  Value MUST be null.  Note this is mainly for purpose of
   being able use union types to define nullability.  If this type
   is not included in a union, null values are not allowed (the
   primitives listed above do not allow nulls on their own).

The way I read this text is that 'mainly' does not mean 'always'. To me, it means that if the null type is used by itself, it is ok too.

Could you indicate how you decided that only 'object' and 'array' are allowed in the first level of a schema ? And would you be willing to accept a pull request for a change to accept other types than 'object' and 'array' for the root object of a schema ?

Thanks and regards.


I think I found this limitation outside the draft document. I see no reason to leave it in. feel free to change it.


oh, and you're welcome. ;)

@oferei oferei closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.