MLE JavaScript Support for JSON

Supported conversions between JavaScript and the JSON data type.

Values of the SQL JSON type can be converted to and from JavaScript values. The type mapping between the SQL JSON type and JavaScript values is aligned with type mappings employed by the node-oracledb driver.

Note:

For more information about node-oracledb and the JSON data type, see the node-oracledb documentation.

Values of the SQL JSON type are converted to JavaScript values as follows:

  • If the JSON value is an object, it is converted to an equivalent JavaScript object by converting all fields of the input object.

  • If the JSON value is an array, it is converted to an equivalent JavaScript array by converting all elements of the input array.

  • If the JSON value is a scalar value, it is converted to an equivalent value according to the type mapping in Table A-3.

Table A-3 Mapping from JSON Attribute Types and Values to JavaScript Types and Values

JSON Attribute Type or Value JavaScript Type or Value
null null
false false
true true
NUMBER Number
VARCHAR2 String
RAW Uint8Array
CLOB String
BLOB UintArray
DATE Date
TIMESTAMP Date
INVERVAL YEAR TO MONTH OracleIntervalYearToMonth
INTERVAL DAY TO SECOND OracleIntervalDayToSecond
BINARY_DOUBLE Number
BINARY_FLOAT Number
Arrays Array
Objects A plain JavaScript Object

Values of a JavaScript type are converted to the SQL JSON type as follows:

  • If the JavaScript value matches one of the scalar types in the first column of Table A-4, it is converted to a JSON value of the corresponding type.

  • If the JavaScript value is an array, it is converted to a JSON array by converting all elements of the array. Note that Uint8Array values are treated as scalars as opposed to arrays, so Uint8Array values are converted to the type RAW, not to a JSON array.

  • If the JavaScript value is an object that is neither an array nor matches any of the JavaScript types/ classes listed in Table A-4, it is converted to a JSON object. Each field of the object is converted according to the appropriate mappings.

Table A-4 Mapping from JavaScript Types and Values to JSON Attributes and Values

JavaScript Type or Value JSON Attribute Type or Value
null null
undefined null
string VARCHAR2
true true
false false
Uint8Array RAW
Number NUMBER
Date DATE
OracleNumber NUMBER
OracleDate DATE
OracleTimestamp TIMESTAMP
OracleTimestampTZ TIMESTAMP WITH TIME ZONE
OracleIntervalYearToMonth INVERVAL YEAR TO MONTH
OracleIntervalDayToSecond INTERVAL DAY TO SECOND
Array Array
Object Object