Categories:

Conversion functions , Semi-structured and structured data functions (Array/Object)

TO_OBJECT¶

Converts the input value to an OBJECT:

  • For a VARIANT value containing an OBJECT, returns the OBJECT.

  • For NULL input, or for a VARIANT value containing only JSON null, returns NULL.

  • For an OBJECT, returns the OBJECT itself.

  • For all other input values, reports an error.

Syntax¶

TO_OBJECT( <expr> )
Copy

Arguments¶

expr

An expression that evaluates to a VARIANT that contains an OBJECT.

Returns¶

The data type of the returned value is OBJECT.

Examples¶

This demonstrates simple usage of the TO_OBJECT function:

Create a table and insert a value of type VARIANT. (The function PARSE_JSON returns a VARIANT.)

CREATE TABLE t1 (vo VARIANT);
INSERT INTO t1 (vo) 
    SELECT PARSE_JSON('{"a":1}');
Copy

Call the TO_OBJECT function:

SELECT TO_OBJECT(vo) from t1;
+---------------+
| TO_OBJECT(VO) |
|---------------|
| {             |
|   "a": 1      |
| }             |
+---------------+
Copy