title: How do you combine data in a Scala dataframe and output it as JSON objects?
body: <p>This is slightly hard to explain for me so I'll do my best. Here is the given data set:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Name</th>
  <th>Car Brand</th>
  <th>Car Model</th>
  <th>Car Color</th>
  <th>Year Bought</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>Tom</td>
  <td>Toyota</td>
  <td>Corolla</td>
  <td>Black</td>
  <td>2009</td>
  </tr>
  <tr>
  <td>Tom</td>
  <td>Hyundai</td>
  <td>Kona</td>
  <td>Blue</td>
  <td>2010</td>
  </tr>
  <tr>
  <td>Tom</td>
  <td>Kia</td>
  <td>Soul</td>
  <td>Red</td>
  <td>2011</td>
  </tr>
  <tr>
  <td>Bob</td>
  <td>Mazda</td>
  <td>CX-30</td>
  <td>Red</td>
  <td>2008</td>
  </tr>
  <tr>
  <td>Bob</td>
  <td>BMW</td>
  <td>X1</td>
  <td>Blue</td>
  <td>2014</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>With the given data set, I want to condense it based on name and just put all the cars into a list and output it out as JSON objects on separated lines in file. For the above data set, the output should look like this:</p>
  <pre><code>{
      &quot;name&quot;: &quot;Tom&quot;,
      &quot;Cars&quot;: [{
          &quot;CarSpecifications&quot;: {
              &quot;Brand&quot;: &quot;Toyota&quot;,
              &quot;Model&quot;: &quot;Corolla&quot;,
              &quot;Color&quot;: &quot;Black&quot;
          },
          &quot;YearBought&quot;:2009
       }, 
       {
          &quot;CarSpecifications&quot;: {
              &quot;Brand&quot;: &quot;Hyundai&quot;,
              &quot;Model&quot;: &quot;Kona&quot;,
              &quot;Color&quot;: &quot;Blue&quot;
          },
          &quot;YearBought&quot;:2010
       },
       {
          &quot;CarSpecifications&quot;: {
              &quot;Brand&quot;: &quot;Hyundai&quot;,
              &quot;Model&quot;: &quot;Kona&quot;,
              &quot;Color&quot;: &quot;Blue&quot;
          },
          &quot;YearBought&quot;:2011
      }]
  }
  
  {
      &quot;name&quot;: &quot;Bob&quot;,
      &quot;Cars&quot;: [{
          &quot;CarSpecifications&quot;: {
              &quot;Brand&quot;: &quot;Mazda&quot;,
              &quot;Model&quot;: &quot;CX-30&quot;,
              &quot;Color&quot;: &quot;Red&quot;
          },
          &quot;YearBought&quot;:2008
       }, 
       {
          &quot;CarSpecifications&quot;: {
              &quot;Brand&quot;: &quot;BMW&quot;,
              &quot;Model&quot;: &quot;X1&quot;,
              &quot;Color&quot;: &quot;Blue&quot;
          },
          &quot;YearBought&quot;:2014
       }]
  }
  </code></pre>
  <p>How could I accomplish these transformations using Scala and Scala Dataframes?</p>