Use of json-schema to validate json


We are developing a platform designed to collect data from several applications and we are using Parse to make the interface between the applications and the platform. Different classes of objects will be sent by the applications, and we want to use json-schema to validate them. Our problem is that the schema used by Parse is not compatible with json-schema, so we need to skip the validation made by Parse and implement the validation ourself.

For now we think of using a generic class in Parse named jsonSchemaData which will contain the schema URL and the data json will be in the data field:

module.exports = {
  className: "jsonSchemaData",
  fields: {
    schemaURL: {type: "String"},
    data: {type: "Object"}

The validation will be done in the beforeSave hook in Parse cloud code.

We wonder if we really need to do this complicated stuff. Ideally we would want to uses classes which do not use the Parse schema at all, so the only validation would be done by us in the cloud code and we could have different classes instead of using a generic one. Is there a way to do something like that?

Hi @nicolas. I had a hard time trying to understand your problem. Maybe if you give an example of what you want to achieve could help. Maybe you don’t need to use classes. Why don’t you validate only using the cloud code functions?

Hi, thanks for your answer.

In my example above, the json which will be sent by the applications will look like:

  "schemaURL": "",
  "data": {
    "score": 123,
    "playerName": "Sean Plott",
    "cheatMode": false

To get all the objects of type GameScore, applications will need to make the request:

curl --request GET \
  --url \
  -H "X-Parse-Application-Id: you_app_id" \
  -H "X-Parse-Master-Key: your_master_key" \
  --get \
  --data-urlencode 'where={"schemaURL":""}'

This is heavier than in the original example from the Parse documentation ( I was wondering if we could find a way where applications would communicate the same way as in the original example, but where the json would be validated against json-schema instead of Parse schema. I’m not sure it’s possible though, so maybe the way we are doing is fine for what we want to do.

I believe it is not a common use case and there is nothing ready-to-use for this. But, I understand that this schema.json is in “Parse” format, wight? Maybe you can try to use one of the internal classes of Parse Server to do the validation for you. Take a look in the link below. It may help you.

No in fact we use json-schema from The validation can easily be done with the npm package jsonschema. We preferred to use json-schema over Parse schema because it is more standard.