title: NodeJS rest api which return response similar like Java Map e.g. Map<String,List<Class>>
body: <p>I am having 2 tables <strong>product_categories</strong> and <strong>product_sub_categories</strong> and these table columns are as follows:<br>
  <strong>product_categories:</strong><br>
  category_id category_name created_by created_date updated_by updated_date
  <strong>product_sub_categories:</strong><br>
  sub_category_id category_id sub_category_name created_by created_date updated_by updated_date</p>
  <p>I am able to fetch product categories and sub_categories like:<br></p>
  <pre><code>//show all Category
  route.get('/getAllCategory',(req, res) =&gt; {
    let sql = &quot;SELECT * FROM product_categories&quot;;
    let query = conn.query(sql, (err, results) =&gt; {
      if(err) throw err;
      res.send(JSON.stringify({&quot;status&quot;: 200, &quot;error&quot;: null, &quot;response&quot;: results}));
    });
  });
  //show all SubCategory
  route.get('/getAllSubCategory',(req, res) =&gt; {
    let sql = &quot;SELECT * FROM product_sub_categories&quot;;
    let query = conn.query(sql, (err, results) =&gt; {
      if(err) throw err;
      res.send(JSON.stringify({&quot;status&quot;: 200, &quot;error&quot;: null, &quot;response&quot;: results}));
    });
  });
  </code></pre>
  <p><strong>The response of getAllCategory:<br></strong></p>
  <pre><code>{
      &quot;status&quot;: 200,
      &quot;error&quot;: null,
      &quot;response&quot;: [
          {
              &quot;category_id&quot;: 1,
              &quot;category_name&quot;: &quot;Baby Care&quot;,
              &quot;created_by&quot;: &quot;admin&quot;,
              &quot;created_date&quot;: &quot;2020-05-31T09:39:06.000Z&quot;,
              &quot;updated_by&quot;: &quot;admin&quot;,
              &quot;updated_date&quot;: &quot;2020-05-31T09:39:06.000Z&quot;
          },
          {
              &quot;category_id&quot;: 2,
              &quot;category_name&quot;: &quot;Personal Care&quot;,
              &quot;created_by&quot;: &quot;admin&quot;,
              &quot;created_date&quot;: &quot;2020-05-31T09:43:09.000Z&quot;,
              &quot;updated_by&quot;: &quot;admin&quot;,
              &quot;updated_date&quot;: &quot;2020-05-31T09:43:09.000Z&quot;
          }
      ]
  }
  </code></pre>
  <p><strong>The response of getAllSubCategory:<br></strong></p>
  <pre><code>{
      &quot;status&quot;: 200,
      &quot;error&quot;: null,
      &quot;response&quot;: [
          {
              &quot;sub_category_id&quot;: 35,
              &quot;category_id&quot;: 1,
              &quot;sub_category_name&quot;: &quot;Baby Food&quot;,
              &quot;created_by&quot;: &quot;admin&quot;,
              &quot;created_date&quot;: &quot;2020-06-09T16:54:15.000Z&quot;,
              &quot;updated_by&quot;: &quot;admin&quot;,
              &quot;updated_date&quot;: &quot;2020-06-09T16:54:15.000Z&quot;
          },
          {
              &quot;sub_category_id&quot;: 36,
              &quot;category_id&quot;: 1,
              &quot;sub_category_name&quot;: &quot;Diapers &amp;amp; Wipes&quot;,
              &quot;created_by&quot;: &quot;admin&quot;,
              &quot;created_date&quot;: &quot;2020-06-09T16:55:05.000Z&quot;,
              &quot;updated_by&quot;: &quot;admin&quot;,
              &quot;updated_date&quot;: &quot;2020-06-09T16:55:05.000Z&quot;
          },
          {
              &quot;sub_category_id&quot;: 27,
              &quot;category_id&quot;: 2,
              &quot;sub_category_name&quot;: &quot;Skin Care&quot;,
              &quot;created_by&quot;: &quot;admin&quot;,
              &quot;created_date&quot;: &quot;2020-06-09T16:54:15.000Z&quot;,
              &quot;updated_by&quot;: &quot;admin&quot;,
              &quot;updated_date&quot;: &quot;2020-06-09T16:54:15.000Z&quot;
          },
          {
              &quot;sub_category_id&quot;: 28,
              &quot;category_id&quot;: 2,
              &quot;sub_category_name&quot;: &quot;Hair Care&quot;,
              &quot;created_by&quot;: &quot;admin&quot;,
              &quot;created_date&quot;: &quot;2020-06-09T16:55:05.000Z&quot;,
              &quot;updated_by&quot;: &quot;admin&quot;,
              &quot;updated_date&quot;: &quot;2020-06-09T16:55:05.000Z&quot;
          }       
      ]
  }
  </code></pre>
  <p>But I want to merge these into one so that I can get response like:<br> { &quot;CategoryName1&quot;:[ listOfSubCategory_ofCategoryName1],<br> &quot;CategoryName2&quot;:[ listOfSubCategory_ofCategoryName2]}<br> Sample Example:<br></p>
  <pre><code>{
      &quot;Baby Care&quot;: [
          {
              &quot;sub_category_id&quot;: &quot;35&quot;,
              &quot;sub_category_name&quot;: &quot;Baby Food&quot;
          },
          {
              &quot;sub_category_id&quot;: &quot;36&quot;,
              &quot;sub_category_name&quot;: &quot;Diapers &amp;amp; Wipes&quot;
          }
      ],
      &quot;Personal Care&quot;: [
          {
              &quot;sub_category_id&quot;: &quot;27&quot;,
              &quot;sub_category_name&quot;: &quot;Skin Care&quot;
          },
          {
              &quot;sub_category_id&quot;: &quot;28&quot;,
              &quot;sub_category_name&quot;: &quot;Hair Care&quot;
          }
      ]
  }
  </code></pre>
  <p>Any suggestions will be greatly appreciated.</p>