FOR JSON Statement

You can execute a SQL query against your database and return the results as a JSON document by using the FOR JSON clause in a SELECT statement.

JavaScript Object Notation (JSON) is a language-independent, text-based data interchange format developed for the serialization of JavaScript data. JSON also represents two structured types: objects and arrays. For more details about JSON format, see http://www.json.org

Syntax

...For JSON mode

mode:
   RAW | AUTO | EXPLICIT

Parameters

Examples

Usage

The FOR JSON clause can be used in any SELECT statement, including subqueries, queries with a GROUP BY clause or aggregate functions, and view definitions. Using the FOR JSON clause represents relational data as a JSON array composed of arrays, objects, and scalar elements.

The format for the alias directive is

[encapsulating_object!tag!name!qualifier]
where:

Standards

ANSI SQL – Compliance level: Transact-SQL extension.

Permissions

None