JSON2BSON

The JSON2BSON function converts the specified JSON document in string format to an equivalent binary representation in BSON format. If you are using the JSON_VAL function to retrieve JSON field values from a JSON document, that document must be in BSON format.

Note: The output of this function is still in the original, modified IBM BSON format that was used prior to Db2® version 11.1.4.4.
Read syntax diagramSkip visual syntax diagram JSON2BSON ( injson )

The schema is SYSTOOLS.

injson
An expression that is JSON data in text format.

The result is a BLOB(16 MB) that contains the converted BSON value. If the input string contains an invalid JSON format, or if the converted value cannot fit into a BLOB(16 MB), an error is returned.

Example

Db2 Inserting into a Db2 column requires the use of the JSON2BSON function. The JSON2BSON function and BSON2JSON are used to transfer data in and out of a traditional Db2 BLOB column. Input to the JSON2BSON function must be a properly formatted JSON document. If the document does not follow proper JSON rules, you will get an error code from the function.
INSERT INTO TESTJSON VALUES
     ( JSON2BSON('{Name:"George"}'));