title: SQL Server : query columns to JSON object with group by
body: <p>I have a table with 3 columns, I want to query that table such that the result will be a JSON object. </p>
  
  <p>Sample data looks like this:</p>
  
  <pre><code> CREATE TABLE #Test (ValueV INT, KEYS NVARCHAR (100), ID INT) 
  
   INSERT INTO #Test 
   VALUES (1, N'ChangeAdress 19 - 21', 200),
          (1, N'ChangeAdress 20 - 22', 200),
          (1, N'ChangeAdress 22 - 24', 300),
          (1, N'ChangeAdress 23 - 25', 300),
          (2, N'ChangeAdress 24 - 26', 400),
          (2, N'ChangeAdress 25 - 27', 400),
          (3, N'ChangeAdress 26 - 28', 400),
          (3, N'ChangeAdress 27 - 29', 400)
  
   SELECT * FROM #Test
  </code></pre>
  
  <p>My query attempt:</p>
  
  <pre><code> SELECT ID, Keys, ValueV
   FROM #Test  
   GROUP BY ID, keys, ValueV
   FOR JSON AUTO
  </code></pre>
  
  <p>But that returns 1 JSON 'row'. What I want, is one row per group. Group being here ID, Value combination. I have little experience with JSON objects (which is probably visible from this query), so help would be appreciated.</p>
  
  <p>The desired output (but then as JSON per row):</p>
  
  <pre><code> --------------------------------------------------
  |200, 1, ChangeAdress 19 - 21, ChangeAdress 20 - 22|
  |300, 1, ChangeAdress 22 - 24, ChangeAdress 23 - 25|
  |400, 2, ChangeAdress 24 - 26, ChangeAdress 25 - 27|
  |400, 3, ChangeAdress 26 - 28, ChangeAdress 27 - 29|
  </code></pre>
  
  <p>Thanks in advance!</p>