NEW JSON Constructor Examples | Teradata Vantage - NEW JSON Constructor Examples - Advanced SQL Engine - Teradata Database

JSON Data Type

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
17.00
Published
September 2020
Language
English (United States)
Last Update
2021-01-23
dita:mapPath
gzn1554761068186.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1150
lifecycle
previous
Product Category
Teradata Vantageā„¢

Example: Default JSON Constructor

NEW JSON();

Examples: JSON Constructor with Text String Arguments

NEW JSON ('{"name" : "cameron", "age" : 24}')

NEW JSON ('{"name" : "cameron", "age" : 24}', LATIN)

Example: JSON Constructor with Binary Data Arguments

This example illustrates the hex format of a BSON document. It is not expected that hex string literals will be used to create a JSON document in the BSON format. Tokens in the data are indicated by alternating bold and regular font. The various hex values are interpreted as follows:
  • 0x00000016: Overall length of the BSON data
  • 0x02: Indicates that the data following the key is of type 'string'
  • 0x68, 0x65, 0x6C, 0x6C, 0x6F, 0x00: The null-terminated string 'hello', interpreted as the key
  • 0x00000006: The length of the string value that follows the key
  • 0x77, 0x6F, 0x72, 0x6C, 0x64, 0x00: The null-terminated string 'world', interpreted as the value
  • 0x00: The null-terminator to indicate the end of the document

The data represents a JSON document that looks like the following in text format:

{"hello":"world"}
/*Creates a JSON document stored as BSON, explicitly*/
SELECT NEW JSON ('160000000268656C6C6F0006000000776F726C640000'xb, BSON);