I have a JSON validation problem that is passed in the request parameter of a GET request as a serialized string.
What I need to do is parse this serialized string back into JSON and check it with Joi.
Example: Give JSON
{ limit: {size:10, page:0}, filter: {filter_by: 'foo', filter_val: 'foo', from: '1/1/2016',to: '1/1/2016' } }
And this JSON is converted to the query string:
limit%5Bsize%5D=10&limit%5Bpage%5D=0&filter%5Bfilter_by%5D=foo&filter%5Bfilter_val%5D=foo&filter%5Bfrom%5D=1%2F1%2F2016&filter%5Bto%5D=1%2F1%2F2016
I need something like this:
validate: { query: { limit: Joi.someMethodToGetJsonFromString.object().keys({ size: Joi.number(), page: Joi.number() } filter: Joi.someMethodToGetJsonFromString,.object().keys({ filter_by: Joi.string().valid(['option1', 'option2']), filter_val: Joi.string(), from: Joi.date(), to: Joi.date(), } }
Is there anything in Joi that can help in this scenario, or do I need to write special validation functions for it.
source share