Tutorial by Examples

Input table data (People table) IdNameAge1John232Jane31 Query SELECT Id, Name, Age FROM People FOR JSON PATH Result [ {"Id":1,"Name":"John","Age":23}, {"Id":2,"Name":"Jane","Age":31} ]
JSON_VALUE and JSON_QUERY functions parse JSON text and return scalar values or objects/arrays on the path in JSON text. DECLARE @json NVARCHAR(100) = '{"id": 1, "user":{"name":"John"}, "skills":["C#","SQL"]}' SELECT JS...
Join parent objects with their child entities, for example we want a relational table of each person and their hobbies DECLARE @json nvarchar(1000) = N'[ { "id":1, "user":{"name":"John"}, "hobbies":[ {...
When storing JSON documents in SQL Server, We need to be able to efficiently filter and sort query results on properties of the JSON documents. CREATE TABLE JsonTable ( id int identity primary key, jsonInfo nvarchar(max), CONSTRAINT [Content should be formatted as JSON] CHECK...
WITHOUT_ARRAY_WRAPPER option in FOR JSON clause will remove array brackets from the JSON output. This is useful if you are returning single row in the query. Note: this option will produce invalid JSON output if more than one row is returned. Input table data (People table) IdNameAge1John232J...
OPENJSON function parses JSON text and returns multiple outputs. Values that should be returned are specified using the paths defined in the WITH clause. If a path is not specified for some column, the column name is used as a path. This function casts returned values to the SQL types defined in the...

Page 1 of 1