3

I want to check the JSON schema itself which is syntactically correct, but not semantically .

e.g

{
      "$schema": "http://json-schema.org/draft-07/schema#",
      "$id": "http://example.com/root.json",
      "type": "object",
      "required": [
        "checked"
      ],
      "properties": {
        "checked": {
          "$id": "#/properties/checked",
          "type_invalid":"string"
        }
      }
    }

In the above example has type_invalid key which is incorrect it should be type. Is there any way to validate JSON schema itself?

for reference:I am using ajv to validate JSON against JSON schema.

Community
  • 1
  • 1
eagle
  • 312
  • 1
  • 13
  • There is no existing tooling to do this, although I highly expect it will be developed this year. The admin team were discussing it this week as something we want, and there may soon be people to work on it. – Relequestual Jan 08 '19 at 09:30
  • You COULD copy the existing meta-schema, and modify it to not allow additional properties, and then use that to validate your schemas. – Relequestual Jan 08 '19 at 09:30
  • @Relequestual Thanks for the solution, this worked for me! – eagle Jan 08 '19 at 10:15
  • I'll add this as an answer for you to accept. – Relequestual Jan 08 '19 at 10:15
  • That will be really helpful – eagle Jan 08 '19 at 10:16
  • but this will not giving me proper error that which properties is invalid(Error: schema is invalid: data.properties['checked'] should NOT have additional properties) – eagle Jan 08 '19 at 10:18
  • That (error output) depends on the library you use. For draft-7, there is no standard way to report errors. This has been defined in the upcoming release of draft-8. – Relequestual Jan 08 '19 at 10:20

1 Answers1

1

You could copy the existing meta-schema, and modify it to not allow additional properties, and then use that to validate your schemas.

Relequestual
  • 11,631
  • 6
  • 47
  • 83