Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Joi object key type

I have object with dynamic string keys with string values,

{
  [string]: string
}

how can I do this?

Joi.object().keys({
  [Joi.string()]: Joi.string()
})

not working :(

like image 946
Jackson Avatar asked Jul 24 '26 11:07

Jackson


1 Answers

You want to use Joi.object().pattern(). From the Joi docs, this lets you provide:

A pattern that can be either a regular expression or a joi schema that will be tested against the unknown key names.

const schema = Joi.object().pattern(
    Joi.string(), Joi.string()
)
like image 175
duncanhall Avatar answered Jul 27 '26 03:07

duncanhall