Formats results of SELECT query as JSON text. FOR JSON PATH clause is added after query:
SELECT top 3 object_id, name, type, principal_id FROM sys.objects
FOR JSON PATH
Column names will be used as keys in JSON, and cell values will be generated as JSON values. Result of the query would be an array of JSON objects:
[
{"object_id":3,"name":"sysrscols","type":"S "},
{"object_id":5,"name":"sysrowsets","type":"S "},
{"object_id":6,"name":"sysclones","type":"S "}
]
NULL values in principal_id column will be ignored (they will not be generated).