Validate nested object properties in javascript