Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

326
Vistas
Joi default value for empty array

I am struggling with the syntax for providing a default value to an empty and/or missing array key.

Joi.object({
    items: Joi.array().empty([]).items(Joi.number()).default([42]),
})

{ 
    items: []
}
or
{
}

In both cases I would want the default value of [42] to be substituted into the object. I'm assuming that I have to indicate that an empty array is invalid in some way, but I'm not sure how. I have also tried setting min(1) on items, but that doesn't work either (it flags the object as invalid, but does not substitute the default value).

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Sorry, posted this too soon. This works:

Joi.object({
    items: Joi.array().optional().empty(Joi.array().length(0)).default([42]),
})
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda