Skip to content
Advertisement

How do I get this JSON output?

I need to create the following JSON from SQL server 2016.

I tried SQL queries using JSON AUTO, JSON PATH and ROOT as shown below but none of them gets me the desired output.

Current result:

Any help is highly appreciable..

Advertisement

Answer

You can try this query:

Example

https://dbfiddle.uk/?rdbms=sqlserver_2016&fiddle=88bc66da55ff918b6550dd738aecb244

Results

Quite frankly, I didn’t know how to do it until I saw examples below:

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement