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);