title: How to validate user input nested object using JOI
body: <p>How to validate nested object using JOI in nodejs (&quot;joi&quot;: &quot;^17.3.0&quot;)</p>
  <pre><code>const Joi = require(&quot;joi&quot;);
  
  const Validation = (data) =&gt; {
    const schema = Joi.object({
      details: {
        firstname: Joi.string().required(),
        lastname: Joi.string().required(),
      },
    });
    return schema.validate(data);
  };
  
  module.exports = {
    Validation,
  };
  </code></pre>
  <p>req.body sample</p>
  <pre><code>{
      &quot;details&quot;: {
          &quot;firstname&quot;: &quot;Fname&quot;,
          &quot;lastname&quot;: &quot;Lname&quot;
      }
  }
  </code></pre>
  <p>Validation(req.body)</p>
  <p><strong>Error message I'm getting &quot;&quot;details.firstname&quot; is required if i'm not sending firstname property. how to get proper message like &quot;firstname required&quot;</strong></p>