I am using React application I have an issue I want to validate the JSON file is empty or not, I know how to validate {}
this kind empty, But my JSON structure is
{
name:"",
email:"",
dob:"",
password:""
}
I have default structure value how to validation inside the value are empty or not like whole empty check likewise
CodePudding user response:
Is this what you're looking for:
myJSON = {
name:"",
email:"",
dob:"",
password:""
}
let jsonValid = true
Object.keys(myJSON).forEach((key)=> {
if(myJSON[key] == "") {
valid = false
}
})
console.log(jsonValid)
It iterates over the each key of the JSON object, if the key's value is an empty string, it will change the value of the jsonValid variable to false/