Blog

More reasons to use Collections - Introducing JSON Schema Validation Beta

It's time to introduce some more powerful features. So far, thousands of Collections are created and are being used heavily.

As of now, we are working on Query Builder, but to make the Collections more powerful and more useful, we are introducing Schema Validations. Now before you Create or Update your bins, you can now Validate the Schema using Schema Docs Feature.

You can create Scema Docs, which are nothing but a Meta Validation against which, the records will be validated. Let me show you how:

Creating Schema Docs

In-order to Create Schema Docs, you can either create the via Schema Docs Create API or you can Create from the User Dashboard.

Consider following Schema Validation Object, the aim is to maintain a Collection of Users and then, we need to validate these bins every time before we Create or Update them.

Persons Schema
{
  "$id": "https://example.com/person.schema.json",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Person",
  "type": "object",
  "properties": {
    "firstName": {
      "type": "string",
      "description": "The person's first name."
    },
    "lastName": {
      "type": "string",
      "description": "The person's last name."
    },
    "age": {
      "description": "Age in years which must be equal to or greater than zero.",
      "type": "integer",
      "minimum": 0
    }
  }
}

The above will validate a bin where the Data would look somewhat like this (which is valid):

{
  "firstName": "John",
  "lastName": "Doe",
  "age": 21
}

You can now use the above Persons Schema and create a Schema Doc for the same.

Once the above is created under Schema Docs, you can now attach it with one of your existing Collection like:

Once you select the Add Schema option, you can select the Schema you want to attach to that Collection, for example:

Once the Schema Doc is attached to a Collection, this will now enable the Validation on every Bin Created or Updated under that collection, like:

Thus, the above will prevent one from creating any random record in the Collection. You can also detach a Schema Doc from a Collection using Edit Collection option.

A couple of things to note here. The validation happens only when the Bins are Created or Updated. Note that we do not validate these records whenever a Schema Doc is attached to a Collection. The previous records will not be validated. Service is in Beta, so expect some bugs in the API & the Dashboard. We are actively working towards fixing these issues and we will enhance the feature more after receiving valuble feedback from our users.

Keep Binning!