Joi: Validate a nested array of objects with properties

Created on 10 Jan 2016  路  4Comments  路  Source: sideway/joi

is it possible to validate an array of nested objects and their properties?

 {
    "text": "some text here...",
    "tags": [
        {
            "id": "0",
            "tag": "travel"
        },
        {
            "id": "98023",
            "tag": "Skydive"
       }
    ]
}

Is validating the objects and properties in the array of tags possible??

support

Most helpful comment

Got it sorted ;)

const tagSchema = {
    id: Joi.number(),
    tag: Joi.string().min(2).regex(/^[A-Za-z]+$/).trim()
};

exports.createPostSchema = Joi.object().keys({
    text: Joi.string().min(1).max(255).required().trim(),
    tags: Joi.array().min(1).items(Joi.object(tagSchema)).required()
}).with('text', 'tags');

All 4 comments

Got it sorted ;)

const tagSchema = {
    id: Joi.number(),
    tag: Joi.string().min(2).regex(/^[A-Za-z]+$/).trim()
};

exports.createPostSchema = Joi.object().keys({
    text: Joi.string().min(1).max(255).required().trim(),
    tags: Joi.array().min(1).items(Joi.object(tagSchema)).required()
}).with('text', 'tags');

Doesn't work for me

"@hapi/joi": "^15.1.0"

Not nearly enough information to help you @oreshkoandrei, open another issue with more details.

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mohamadresaaa picture mohamadresaaa  路  3Comments

n-sviridenko picture n-sviridenko  路  3Comments

a-c-m picture a-c-m  路  3Comments

sergibondarenko picture sergibondarenko  路  3Comments

normancarcamo picture normancarcamo  路  3Comments