
Now, when we have opened JSON we can do anything. Use Case 1: Inserting JSON content in table
Udig import json update#
In this post you will see how easily you can insert and update tables using JSON objects. This function can also open nested/hierarchical JSON object (I will describe this in a separate post). In that case, it will return a multi-row table (each table row will match one JSON object in array) instead of single row table. OPENJSON function will also work with JSON arrays. In this example, we have opened json object and mapped fields to columns by name. Example of query that opens content of JSON variable is shown in the following listing:įirstName nvarchar(50), lastName nvarchar(50),ĭateOfBirth datetime2, spouse nvarchar(50)) OPENJSON function will parse JSON object, match properties in JSON object with column names and convert their values to specified types. In the WITH clause you can define schema of the returned rows with names of columns and their types. Syntax of OPENJSON function that transforms JSON document to rowset looks like: These rows can be imported into tables or they can be used to update existing records in tables. OPENJSON table value function transforms JSON object to one or many rows. We need a way to import JSON documents into SQL tables. These JSON documents might be values sent to REST web services, information from sensors, records from log files formatted as JSON, or other system transform information as JSON during data transfer.

Our database receives JSON documents from external systems. In this post I will show how you can directly insert/update table rows using JSON objects.

In SQL Server 2016 will be added a new table value function that can transform JSON text into row(s).
