6

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 :(

Jackson
  • 884
  • 2
  • 13
  • 22
  • 1
    Possible duplicate of [Is there a way to validate dynamic key names in a Joi schema?](https://stackoverflow.com/questions/43050870/is-there-a-way-to-validate-dynamic-key-names-in-a-joi-schema) – Ankh Aug 15 '18 at 09:10

1 Answers1

10

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()
)
duncanhall
  • 11,035
  • 5
  • 54
  • 86