title: Convert a string to a nested JavaScript object or JSON
body: <p>I have the following string:</p>
  <pre class="lang-js prettyprint-override"><code>let str = &quot;modules.mas.mas-helper-provider.assets.locales&quot;;
  </code></pre>
  <p>and would like to convert it to a nested JavaScript  object (JSON), something like this result:</p>
  <pre class="lang-json prettyprint-override"><code>{
    &quot;modules&quot;: {
      &quot;mas&quot;: {
        &quot;mas-helper-provider&quot;: {
          &quot;assets&quot;: {
            &quot;locales&quot;: &quot;&quot;
          }
        }
      }
    }
  }
  </code></pre>