title: convert query output into json format in sql server
body: <p>I want to display the below query output  into JSON Format(Required output format)</p>
  
  <pre><code>select ApplicationID ApplicationID ,Roleid Roles from UserRoles where userid=11 and applicationid is not null 
  
  Output
  
  ApplicationID  Roles
  1                1
  1                5
  3                5
  </code></pre>
  
  <p>i want to display below format i am using sql server 2016</p>
  
  <pre><code>Required output Format:
  [{"ApplicationID":1,"Roles":[1,5]},{"ApplicationID":3,"Roles":[5]}]
  </code></pre>