Validation of JSON schema structure

Hi all,

I am trying to find out if it is possible to ‘validate’ the structure of a given piece of JSON against the JSONforms validation?

For context, I have a custom CodeEditor component which is essentially a wrapped Ace Editor field, which accepts JSON to be entered and this JSON will be sent to a backend and transformed into a JSON forms schema and we want to improve the UX by adding in some validation that will help pick up any errors in the JSON entered before being submitted to the backend incase of any errors.

I have had a look around JSONforms and Ajv but there doesn’t seem to be much if anything for testing a ‘structure’ of the JSON to be used for the schema itself that I could see.

I did see a validateSchema method with Ajv but basically that will take any object which is valid in terms of syntax and say it is valid, where as I want it to look for things such as a properties array being present etc and ideally the individual properties to be valid also.

Is there a way that this can be done?


Hi @thomasbritton,

The JSON Schema spec is very lenient and does not really mandate any property. Also it allows a lot of shortcuts. Additional properties are also not forbidden.

Therefore most objects will pass a generic JSON Schema validation.

In case you want to have a stricter validation, for example to enforce a certain style or make the type property mandatory then you will need to perform the validation yourself. For example by specifying a more strict JSON Schema for your expected JSON Schemas structure.