title: SQL to JSON parent/child relationship
body: <p>I have a table in my Microsoft SQL Server 2017 that looks like this:</p>
  
  <pre><code>+----+-------+----------+-------+-----------+
  | ID | Level | ParentID | IsEnd | SomeText  |
  +----+-------+----------+-------+-----------+
  |  1 |     1 |    null  |     1 |   abc     |
  |  2 |     1 |    null  |     1 |   asd     |
  |  3 |     2 |    1     |     1 |   weqweq  |
  |  4 |     2 |    1     |     0 |   lkjlkje |
  |  5 |     3 |    4     |     1 |   noonwqe |
  |  6 |     3 |    4     |     0 |   wet4t4  |
  +----+-------+----------+-------+-----------+
  </code></pre>
  
  <p>And I would like to output a json string:</p>
  
  <pre><code>[{  ID: 1,
  SomeText: 'abc',
  Child2: [{
          ID: 3,
          SomeText: 'weqweq'
      }, {
          ID: 4,
          SomeText: 'lkjlkje',
          Child3: [{
                  ID: 5,
                  SomeText: 'noonwqe'
              }, {
                  ID: 6,
                  SomeText: 'wet4t4'
              }
          ]}
          ] 
  }]
  </code></pre>
  
  <p><code>IsEnd</code> is a flag to know where you reached the last level.</p>