0

I have to provide to the client the possibility to upload his own JSON Schema.

Is there a way to validate that the JSON Schema provided by the user is a valid JSON Schema and not just data?

I am using Java with this library https://github.com/networknt/json-schema-validator

UPDATE:

I am having the following schema:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "title": "car",
  "description": "representation of car",
  "type": "object",
  "required": [
    "id",
    "make",
    "age",
    "model",
    "mileage",
    "fuel"
  ],
  "properties": {
    "id": {
      "type": "string"
    },
    "make": {
      "type": "string"
    },
    "model": {
      "type": "string"
    },
    "age": {
      "type": "integer",
      "minimum": 0
    },
    "color": {
      "type": "string"
    },
    "power_in_hp": {
      "type": "integer",
      "minimum": 0
    },
    "fuel": {
      "enum": ["gasoline", "diesel", "hybrid", "electric"]
    },
    "mileage": {
      "type": "integer",
      "minimum": 0
    }
  }
}

I need to know whether this is a valid JSON Schema and not JSON data. An example for JSON data is provided here:

{
    "id": "1f5abf56-7210-481a-b2d5-324b6e0f6358",
    "make": "Volkswagen",
    "model": "Lupo",
    "age": 18,
    "color": "black",
    "power_in_hp": 61,
    "fuel": "diesel",
    "mileage": 401234
  }
Benji
  • 13
  • 3

1 Answers1

2

Yes, you want to validate that JSON against the JSON Schema meta schema.

It will make sure the schema is valid as far as possible, but not that it makes sense or isn't illogical or impossible.

Relequestual
  • 11,631
  • 6
  • 47
  • 83