Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

188
Views
Ajv, ajv-errors define custom message for nested properties

I am using Ajv version 6 for error validation. I am also using ajv-errors for custom messages. I need to define custom error messages for nested properties, but cannot figure out how to do it. I cant seem to find such a case in the ajv-errors documentation. I'm trying to do something like the following

var Ajv = require('ajv'/*@6.11.0*/);
var ajv = new Ajv({allErrors: true, jsonPointers: true});

require('ajv-errors/*@1.0.1*/')(ajv /*, {singleError: true} */);


var schema = {
  type: 'object',
    properties: {
      foo: {
       'type': 'object',
       properties: {
        bar: { type: 'string', minLength: 2 }
       }
      },
    },
  errorMessage: {
    properties: {
      'foo.bar': 'foo.bar should be string with length >= 2'
    }
  }
};

var validate = ajv.compile(schema);
// console.log(validate({foo: 1, bar: 'a'})); // false
console.log(validate({foo: { bar: '' }})); // false
console.log(validate.errors); // processed errors

This does not work off course, any ideas how to make this work?

about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!