SQL Flow Field Guide

FOR JSON

Catalog support for SQL Server 2022 (16.x) and 2025 (17.x)

serializes the rowset to JSON text

What changes

Input
final ordered result rows
Output or change
one nvarchar(max) JSON value

Syntax at a glance

FOR JSON { AUTO | PATH } [ , ROOT [ ( 'RootName' ) ] ] [ , INCLUDE_NULL_VALUES ] [ , WITHOUT_ARRAY_WRAPPER ]

Work example

A client needs FOR JSON to serialize a query result into a named document shape.

Use two synthetic rows and specify stable aliases. Check escaping, null handling, and nested property names in the emitted text.

Check your work FOR JSON. The output from FOR JSON parses as the expected document and preserves the requested field names.

Open Microsoft Learn for full syntax, permissions, and details for your version.