Handling JSON with Mixed Data Types in Node.js: implementing Array of Objects Validation
I'm performance testing and I've been struggling with this for a few days now and could really use some help..... I'm working on a personal project and I'm working on a Node.js application using Express and trying to validate incoming JSON data that contains an array of objects. Each object should have a mix of string and number types, but I keep working with issues where the validation fails unexpectedly, even when the data seems to match the required structure. Hereโs the JSON structure I expect: ```json [ {"name": "Alice", "age": 30}, {"name": "Bob", "age": 25} ] ``` Iโm using `Joi` for validation, and my schema looks like this: ```javascript const Joi = require('joi'); const schema = Joi.array().items(Joi.object().keys({ name: Joi.string().required(), age: Joi.number().integer().min(0).required() })); ``` When I test the validation with the above JSON, it works fine. However, if I modify the JSON to include an object where `age` is a string instead of a number, like so: ```json [ {"name": "Alice", "age": "thirty"}, {"name": "Bob", "age": 25} ] ``` I get the following behavior: ``` ValidationError: "[0].age" must be a number ``` I expected Joi to throw an behavior for the first object only, but it seems to validate the entire array instead, which is correct behavior but not what I want. I want to be able to filter out invalid entries instead of failing the entire validation process. How can I modify my Joi schema or approach to allow partial validation of the array and return the valid entries? Iโve tried using `Joi.array().items(Joi.object().keys(...)).allow(null)` but it didnโt seem to help. Any suggestions or best practices for handling mixed data types in arrays when using Joi? For context: I'm using Javascript on macOS. What am I doing wrong? How would you solve this?