OPENJSON
shreds JSON into rows
What changes
- Input
- JSON text (column, variable, literal), optional path
- Output or change
- rowset: key/value/type, or typed columns from WITH
- Return type
- The columns that the OPENJSON function returns depend on the WITH option. When you call OPENJSON with the default schema - that is, when you don't specify an explicit schema in the WITH clause - the f
Syntax at a glance
OPENJSON( jsonExpression [ , path ] ) [ <with_clause> ]
Work example
Turn JSON object properties or array elements into a rowset for relational queries.
Declare an explicit WITH schema when names, SQL types, or nested paths matter.
Check your work OPENJSON needs database compatibility level 130 or higher and its default schema exposes key, value, and type.
Practice SQL
Open in SQL FlowSELECT item, quantity FROM OPENJSON(N'{"item":"book","quantity":2}') WITH (item nvarchar(20), quantity int);
Open Microsoft Learn for full syntax, permissions, and details for your version.