I have the following assessment which is to Create Array of Favorite Food items object in data.json file.
The Array of Objects should have the following fields :
- Name
- Type
- Price
After writing the JSON data, this file should be imported in loopobject.js.
I tried the above request with the below data.json
{
food:[
{
Name:Apple,
Type:fruit,
Price:100
},
{
Name:pizza,
Type:italian,
Price:370
},
{
Name:Burger,
Type:Mac&Cheese,
Price:310
},
{
Name:salad,
Type:Veg,
Price:50
}
]
}
And with loopobject.js
var json = require('./data.json');
json.forEach(function(object) { console.log(object.Name); });
and the Schema is:
const schema = Joi.array().min(3).has({
Name: Joi.string().required(),
Type: Joi.string().required(),
Price: Joi.number().required(),
});
On submitting the above data.json and loopobject.js I get:
ValidationError: value must be an array
I am not sure how to edit the data.json to make it Array of Objects, as for as I can think the data.json has array of objects.
Can someone help fix the issue on data.json and loopobject.js?
Please note I can't edit the JSON schema