title: How can I parse a string input to match a field in a json?
body: <p><em>i know the question is very unclear and ambiguous, so i'll elaborate:</em></p>
  
  <p><strong>i want to parse a string input from a user, and make it a valid field name that i can access as part of a json.</strong></p>
  
  <hr>
  
  <h2>example:</h2>
  
  <p>assuming we have this json:</p>
  
  <pre><code>var user = 
  {
     id: 1,
     email: 'some@email.com',
     name:
     {
        first: 'stack',
        last: 'overflow'
     }
  };
  </code></pre>
  
  <p>let's say the user input this:</p>
  
  <p><code>enter a valid field: "name.first"</code></p>
  
  <p>i want the app to return this:</p>
  
  <p><code>return user.name.first;</code></p>
  
  <p>or interchangeably:</p>
  
  <p><code>return user['name']['first'];</code></p>
  
  <p><strong>how can i do it without loops and ugly code?</strong></p>
  
  <p>i'm asking because i saw it in couple of open source plugins, like <a href="https://github.com/buunguyen/mongoose-deep-populate" rel="nofollow">mongoose-deep-populate</a>, and there you can input the way i want my users to do.</p>
  
  <p><em>btw, i'm terrible at explaining myself in english, so please critic me if you don't understand and i'll try to rephrase.</em></p>
  
  <p>Thanks in advance!</p>
  
  <p>Amit</p>