JSON_TO_BSON
The JSON_TO_BSON function converts a string containing formatted JSON data to a binary string containing the data formatted as BSON.
- JSON-expression
-
Specifies an expression that returns a character or graphic string value. It must contain formatted JSON data.
If JSON-expression is a JSON array, it will be wrapped using a key name of SYSIBM_ROOT_ARRAY modifying the JSON-expression to be a JSON object.
If a JSON object in JSON-expression contains duplicate keys, only one of the key:value pairs will be included in the result BSON string.
The data type of the result is BLOB(2G).
If the argument can be null, the result can be null; if the argument is null, the result is the null value.
Example
- Read a JSON value from a table and convert it to BSON
format.
CREATE VARIABLE BSONVAR VARBINARY(2000); SELECT JSON_TO_BSON(JSON_COL) INTO BSONVAR FROM TABLE2 WHERE KEY_COLUMN = 27;