title: String path to Json
body: <p>I have the list of paths like below.</p>
  
  <pre><code>var paths = [
      "ubx/ubx-producao/Editora Abril/Exame 1106/FINANCAS_INOCAVAO_STARTUP_BANCOES.mp3",
      "ubx/ubx-producao/Editora Alto Astral/Previsoes signos Fevereiro 2016/aquario-fevereiro.mp3",
      "ubx/ubx-producao/Editora Alto Astral/Previsoes signos Fevereiro 2016/aries-fevereiro.mp3"];
  </code></pre>
  
  <p>I parse to JSON with the code bellow.</p>
  
  <pre><code>let treePath = { };
  
  paths.forEach(path =&gt; {
      let levels = path.split("/");
      let file = levels.pop() 
      let prevLevel = treePath;
      let prevProp = levels.shift()   
  
      levels.forEach(prop =&gt; {
          prevLevel[prevProp] = prevLevel[prevProp] || {};
          prevLevel = prevLevel[prevProp];
          prevProp = prop
      });
      prevLevel[prevProp] = (prevLevel[prevProp] || []).concat([file]);
  });
  </code></pre>
  
  <p>I got the result shown below:
  <img src="https://i.stack.imgur.com/U6rae.png" alt="output result"></p>
  
  <p>My greatest difficulty is to make the output bellow</p>
  
  <pre><code>{
      "text": "ubx",
      "children" : [{
          "text": "ubx-producao",
          "children": [{
              "text": "Editora Abril",
              "children": [{
                  "text": "Exame 1106",
                  "children": [
                      "BRASIL ECONOMIA DUPLA EXPLOSIVAE.mp3","BRASIL ECONOMIA PRONTOS PARA O JANTAR.mp3"]
                  ]
              }]
          },
          {
              "text": "Editora Alto Astral",
              "children": [{
                  "text": "Previsoes signos Fevereiro 2016",
                  "children": ["aquario-fevereiro.mp3", "aquario-fevereiro.mp3.sfk"]
              }]
          }]
      }]
  }
  </code></pre>