How do I convert object to object of types

333 Views Asked by At

How do I convert an object to an object of Joi types/definitions?

I have a bunch of objects that I need to classify. I need to know what each entry is and it needs to be able to drill down through possibly multiple layers of arrays and/or objects (see the example below).

The reason I need this is that I'm using frisbyjs to validate an API response and it takes an object of Joi types to compare against the API response.

Input:

{
    reservation: {
        alterations: [],
        arrival_details: {
            guest_checkin_time_from: {
                formatted_hour: "NOT_SELECTED",
                localized_hour_string: "Select"
            },
            is_bringing_pets: false,
            number_of_adults: 2
        },
        booked_at: "2019-03-15T14:35:28Z",
        cancellation_host_fee: 0
    }
}

Output:

{
    reservation: Joi.object({
        alterations: Joi.array(),
        arrival_details: Joi.object({
            guest_checkin_time_from: Joi.object({
                formatted_hour: Joi.string(),
                localized_hour_string: Joi.string()
            }),
            is_bringing_pets: Joi.bool(),
            number_of_adults: Joi.number()
        }),
        booked_at: Joi.date(),
        cancellation_host_fee: Joi.number()
    })
}
0

There are 0 best solutions below