title: T-SQL JSON transformation
body: <p>I need to change the structure of JSON data I have in a variable into a different structure</p>
  
  <p>Here's the structure I have now: </p>
  
  <pre><code>DECLARE @json NVARCHAR(MAX)
  SET @json =  N'{"meta":{"total_record_count":4870,"total_pages":98,"current_page":97,"per_page":50},"companies":[{"id":"13463591","url":"https://api.mattermark.com/companies/13463591","company_name":"Modula4","domain":"modula4.com"},{"id":"13531979","url":"https://api.mattermark.com/companies/13531979","company_name":"Rae Development Corp","domain":"raedevelopment.com"},{"id":"13537660","url":"https://api.mattermark.com/companies/13537660","company_name":"jBASE","domain":"jbase.com"},{"id":"13537769","url":"https://api.mattermark.com/companies/13537769","company_name":"D2Effects LLC","domain":"bitefx.com"},{"id":"13537784","url":"https://api.mattermark.com/companies/13537784","company_name":"eSyncTraining","domain":"esynctraining.com"},{"id":"13541751","url":"https://api.mattermark.com/companies/13541751","company_name":"Business Computing","domain":"bcinc.net"},{"id":"13553270","url":"https://api.mattermark.com/companies/13553270","company_name":"KNIGHTLING INC.","domain":"knightling.com"},{"id":"13560476","url":"https://api.mattermark.com/companies/13560476","company_name":"Netcentric systems","domain":"netcentricsystems.com"},{"id":"13560643","url":"https://api.mattermark.com/companies/13560643","company_name":"Fortium Solutions, LLC","domain":"fortiumsolutions.com"},{"id":"13561893","url":"https://api.mattermark.com/companies/13561893","company_name":"PMAC SERVICES INC","domain":"pmacservices.com"},{"id":"13587256","url":"https://api.mattermark.com/companies/13587256","company_name":"Bayonet Inc.","domain":"mybayonet.com"},{"id":"13590982","url":"https://api.mattermark.com/companies/13590982","company_name":"IQA","domain":"instrumentalqa.com"},{"id":"13593143","url":"https://api.mattermark.com/companies/13593143","company_name":"Atech Consultants","domain":"atechconsultants.com"},{"id":"13601156","url":"https://api.mattermark.com/companies/13601156","company_name":"Csoft Corp","domain":"csoftcorp.net"},{"id":"13602832","url":"https://api.mattermark.com/companies/13602832","company_name":"Gareth, Inc.","domain":"garethinc.com"},{"id":"13604890","url":"https://api.mattermark.com/companies/13604890","company_name":"Xpaseo","domain":"xpaseo.com"},{"id":"13610146","url":"https://api.mattermark.com/companies/13610146","company_name":"Imagine IT","domain":"imagineit.com"},{"id":"13610923","url":"https://api.mattermark.com/companies/13610923","company_name":"HTS Solutions Pvt Ltd","domain":"htssolutions.org"},{"id":"13619836","url":"https://api.mattermark.com/companies/13619836","company_name":"Tgm Software","domain":"tgmsoftware.com"},{"id":"13622956","url":"https://api.mattermark.com/companies/13622956","company_name":"Inaspan LLC","domain":"inaspan.com"},{"id":"13627130","url":"https://api.mattermark.com/companies/13627130","company_name":"Forerunner Systems Inc","domain":"forerunnersystems.com"},{"id":"13628312","url":"https://api.mattermark.com/companies/13628312","company_name":"Advanced Integrated Solutions, Inc.","domain":"aisconsulting.net"},{"id":"13629029","url":"https://api.mattermark.com/companies/13629029","company_name":"Pounce Consulting","domain":"pouncecorp.com"},{"id":"13629537","url":"https://api.mattermark.com/companies/13629537","company_name":"CloudServe Corporation","domain":"cloudservecorp.com"},{"id":"13635102","url":"https://api.mattermark.com/companies/13635102","company_name":"Leivio Technologies","domain":"leivio.com"},{"id":"13636749","url":"https://api.mattermark.com/companies/13636749","company_name":"Alpen Technology Group","domain":"alpentg.com"},{"id":"13636754","url":"https://api.mattermark.com/companies/13636754","company_name":"National Schedule Masters","domain":"tractime.com"},{"id":"13645065","url":"https://api.mattermark.com/companies/13645065","company_name":"RISA Technologies","domain":"risa.com"},{"id":"13646467","url":"https://api.mattermark.com/companies/13646467","company_name":"Enterprise Answers, LLC","domain":"enterpriseanswers.com"},{"id":"13647801","url":"https://api.mattermark.com/companies/13647801","company_name":"Office Automation Centers Inc","domain":"officeautomationcenter.com"},{"id":"13650810","url":"https://api.mattermark.com/companies/13650810","company_name":"Mozgomedia","domain":"mozgomedia.com"},{"id":"13652763","url":"https://api.mattermark.com/companies/13652763","company_name":"2000 Networking","domain":"network2000-hi.com"},{"id":"13654103","url":"https://api.mattermark.com/companies/13654103","company_name":"Vega Imaging","domain":"vega-imaging.com"},{"id":"13654874","url":"https://api.mattermark.com/companies/13654874","company_name":"Astha Inc.","domain":"asthainc.com"},{"id":"13656103","url":"https://api.mattermark.com/companies/13656103","company_name":"Management Applied Programming","domain":"mapinc.com"},{"id":"13657848","url":"https://api.mattermark.com/companies/13657848","company_name":"4Hilton Inc.","domain":"4hilton.com"},{"id":"13658020","url":"https://api.mattermark.com/companies/13658020","company_name":"FCC Group","domain":"fccgroup.com"},{"id":"13658316","url":"https://api.mattermark.com/companies/13658316","company_name":"Wavelength Datacom, Inc.","domain":"wavdata.com"},{"id":"13661074","url":"https://api.mattermark.com/companies/13661074","company_name":"Xintex Corporation","domain":"xintex.com"},{"id":"13663085","url":"https://api.mattermark.com/companies/13663085","company_name":"DCL Media Services","domain":"onlinecopycorp.com"},{"id":"13667881","url":"https://api.mattermark.com/companies/13667881","company_name":"LMSPros","domain":"lmspros.com"},{"id":"13669354","url":"https://api.mattermark.com/companies/13669354","company_name":"Sujansky \u0026 Associates, LLC","domain":"sujansky.com"},{"id":"13669681","url":"https://api.mattermark.com/companies/13669681","company_name":"Felosoft LLC","domain":"felosoft.com"},{"id":"13669759","url":"https://api.mattermark.com/companies/13669759","company_name":"Collaborative Technologies Inc","domain":"collaborationtech.net"},{"id":"13670474","url":"https://api.mattermark.com/companies/13670474","company_name":"Freight Stream Inc","domain":"freightstream.com"},{"id":"13675681","url":"https://api.mattermark.com/companies/13675681","company_name":"eDimension Consulting","domain":"edimensionconsulting.com"},{"id":"13676806","url":"https://api.mattermark.com/companies/13676806","company_name":"LTT Net Solutions","domain":"lttnetsolutions.com"},{"id":"13678223","url":"https://api.mattermark.com/companies/13678223","company_name":"OCRTI Consulting Corp","domain":"ocrti.com"},{"id":"13679946","url":"https://api.mattermark.com/companies/13679946","company_name":"Mac Networks","domain":"macnetworks.com"},{"id":"13681009","url":"https://api.mattermark.com/companies/13681009","company_name":"NetMost Web Technologies","domain":"netmostwebdesign.com"}],"total_companies":4870,"page":97,"per_page":50}'
  </code></pre>
  
  <p>And here's a sample of the structure I want to achieve:</p>
  
  <pre><code>DECLARE @json NVARCHAR(MAX)
  SET @json = N'[{"companies":{"id":"13681077","url":"https://api.mattermark.com/companies/13681077","company_name":"DeltaBind","domain":"deltabind.com"}}]'  
  </code></pre>
  
  <p>The reason I want to achieve this structure is because I've already tested the sample JSON document with this query &amp; it's returned columnar data in the fashion that I need. </p>
  
  <p><a href="https://i.stack.imgur.com/fTBTN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fTBTN.png" alt="enter image description here"></a></p>
  
  <p>Can someone please assist with the syntax to achieve the desired JSON structure? </p>