Netherlands: Software

Introductie van Micorosoft SQL Server 2016

Issue link:

Contents of this Issue


Page 90 of 212

78 C H A P T E R 5 | Broader data access Note You can find a variety of use cases for JSON in SQL Server at the SQL Server Database Engine blog by searching for articles tagged as JSON, Getting acquainted with JSON structures JSON consists of two basic structures: an object containing one or more properties (also known as name/value pairs), and an ordered array of values. An object is enclosed in braces and includes a name followed by a colon and the value associated with the name. The name must be a string enclosed in double quotation marks, and the value can be a string in double quotation marks, a number, a Boolean value (true or false), null, another object, or an array. Multiple name/value pairs in an object are separated by commas, like this: {"ProductID":709,"Name":"Mountain Bike Socks, M"} An array is enclosed in brackets and can contain comma-separated values represented as a string within double quotation marks, a number, a Boolean value, null, or another object, like this: [{"ProductID":709,"Name":"Mountain Bike Socks, M"}, {"ProductID":937,"Name":"HL Mountain Pedal"}] Note The official language specification for JSON is available in "The JSON Data Interchange Format," at Exporting data to JSON Let's say you have a web application that requests data from your SQL Server database, but it requires the data to be formatted as JSON. Rather than include code in the application to perform the necessary transformations, you can easily export data from SQL Server tables to JSON format by adding the new FOR JSON clause to your SELECT statement. As part of the export process, the database engine converts SQL data types to the appropriate JSON data types, as shown in the following table: Category SQL data type JSON data type Character char nchar varchar nvarchar string Numeric int bigint float decimal numeric number Bit bit Boolean Date and time date datetime datetime2 time datetimeoffset string Binary binary BASE64-encoded string CLR CLR geometry Not supported (returns error)

Articles in this issue

Links on this page

Archives of this issue

view archives of Netherlands: Software - Introductie van Micorosoft SQL Server 2016