jsoneditor
jsoneditor copied to clipboard
Change Json schema validation error message
Hello,
Is there a way to change the validation error message instead of using the default message? Here is what I have tries so far:
onValidationError: function (errors) {
console.debug(errors)
errors.forEach((error) => {
switch (error.type) {
case 'validation': // schema validation error
if(error.schemaPath === "someIdentifier") {
error.message = "Custom Message";
}
break;
case 'customValidation': // custom validation error
break;
case 'error': // json parse error
break;
}
});
},
The custom message is not reflected in the json editor. Any help would be appreciated!
Thank you!
The onValidationError callback is only to get notified about the errors, it cannot be used to change the erorrs.
You can probably use onValidate(json) to roll your own validation the way you like (including using the latest version of the ajv valiator). Here is an example: https://github.com/josdejong/jsoneditor/blob/develop/examples/18_custom_validation.html