Start of change

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.

Read syntax diagramSkip visual syntax diagram JSON_TO_BSON ( JSON-expression )
JSON-expression

Specifies an expression that returns a character or graphic string value. It must contain formatted JSON data.

Start of changeIf 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.End of change

Start of changeIf a JSON object in JSON-expression contains duplicate keys, only one of the key:value pairs will be included in the result BSON string.End of change

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;
End of change