NEW JSON Constructor Examples | VantageCloud Lake - NEW JSON Constructor Examples - Teradata Vantage

Teradata® VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
Product
Teradata Vantage
Published
January 2023
Language
English (United States)
Last Update
2024-04-03
dita:mapPath
phg1621910019905.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
phg1621910019905

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 shows the hex format of a BSON document. Hex string literals are not expected to be used to create a JSON document in the BSON format. Tokens in the data are indicated by alternating bold and regular font. The 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);