JSON2BSON

The JSON2BSON user-defined 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.

Read syntax diagramSkip visual syntax diagramJSON2BSON( injson)

The schema is SYSTOOLS.

injson
An expression that returns a CLOB (JSON document in text format) that is no larger than 16 MB.

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

The following example inserts a row into a table, which contains a BLOB column that holds a JSON document:

INSERT INTO CUSTOMER_LIST 
                  (CUSTID, ADDRESS_LINE1, CITY, STATE, ZIP, PROFILE)
       VALUES('12345',' 333 Oak Street', 'San Jose', 'CA', '95110', 
                   SYSTOOLS.JSON2BSON('{"name":"Joe Stockton", "age":28, "interests":["gardening","camping"]}'));