title: Output key value pairs as JSON from T-SQL query
body: <p>I have an app that needs to be supplied with configuration data as key value pairs in JSON.</p>
  <p>I want to output JSON of key value pairs from a table query.</p>
  <p>The table can have different named items and varying quanities of items.</p>
  <p>TABLE</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>ITEMID</th>
  <th>REPORTID</th>
  <th>NAME</th>
  <th>VALUE</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>29</td>
  <td>caption</td>
  <td>Profit by Product</td>
  </tr>
  <tr>
  <td>2</td>
  <td>29</td>
  <td>bgColor</td>
  <td>#FFFFFF</td>
  </tr>
  <tr>
  <td>3</td>
  <td>29</td>
  <td>showBorder</td>
  <td>0</td>
  </tr>
  <tr>
  <td>4</td>
  <td>29</td>
  <td>showsum</td>
  <td>0</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>SQL</p>
  <pre><code>select .................   FOR JSON PATH
  </code></pre>
  <p>I'm guessing this needs to use a PIVOT?</p>
  <p>Expected JSON</p>
  <pre><code>{&quot;caption&quot;:&quot;Profit by Product&quot;,&quot;bgColor&quot;:&quot;#FFFFFF&quot;,&quot;showBorder&quot;:&quot;0&quot;,&quot;showsum&quot;:&quot;0&quot;}
  </code></pre>
  <p>Appreciate help anyone can provide.</p>