---
title: "Type Conversion Functions"
description: "List of functions that perform type conversions in GSQL."
component: "gsql-ref"
version: "4.3"
module: "querying"
html_url: "/gsql-ref/4.3/querying/func/type-conversion-functions"
canonical_url: "https://www.tigergraph.com/docs/gsql-ref/4.3/querying/func/type-conversion-functions"
markdown_url: "https://www.tigergraph.com/docs/gsql-ref/4.3/querying/func/type-conversion-functions.md"
---

[View as HTML](https://www.tigergraph.com/docs/gsql-ref/4.3/querying/func/type-conversion-functions)

# Type Conversion Functions

The functions on this page are used to convert data from one type to another in the GSQL query language.

## `parse_json_array()`

### Syntax

`parse_json_array( str )`

### Description

Converts a string into a JSON array. The string must be properly formatted, or the function will generate a run-time error. To be properly formatted, besides having the proper nesting and matching of curly braces `{ }` and brackets `[ ]`, each value field must be one of the following:

* a string
* a number
* a boolean
* a JSONOBJECT - Each key of a key-value pair must be a string in double quotes.
* a JSON array

### Return type

`JSONARRAY`

### Parameters

| Parameter | Description | Data type |
| --- | --- | --- |
| `str` | The string to be converted into a JSON array. | `STRING` |

### Example

```javascript
parse_json_array("[123]") -> [123]
```

## `parse_json_object()`

### Syntax

`parse_json_object( str )`

### Description

Converts a string into a JSON object. The string must be properly formatted, or the function will generate a run-time error. To be properly formatted, besides having the proper nesting and matching of curly braces `{ }` and brackets `[ ]`, each value field must be one of the following:

* a string
* a number
* a boolean
* a JSONOBJECT - Each key of a key-value pair must be a string in double quotes, and the quotes need to be escaped with a backlash-escape `\`. However, if you are supplying the string in GraphStudio as a parameter, you do not need the backlash-escape since string values are not enclosed in double quotes.
* a JSON array

### Return type

`JSONOBJECT`

### Parameters

| Parameter | Description | Data type |
| --- | --- | --- |
| `str` | The string to be converted into a JSON object. | `STRING` |

### Example

```javascript
parse_json_object("{\"abc\":123}")  -> {"abc": 123}
```

## `str_to_int ()`

### Syntax

`str_to_int (str)`

### Description

Converts a string to an integer.

### Return type

`INT`

### Parameters

| Parameter | Description | Data type |
| --- | --- | --- |
| `str` | The string to be converted to an integer | `STRING` |

## `to_datetime ()`

### Syntax

`to_datetime ( str )`

### Description

Converts a string value into a `DATETIME` value.

### Return type

`DATETIME`

### Parameters

| Parameter | Description | Data type |
| --- | --- | --- |
| `str` | A string value | `STRING` |

### Example

```javascript
to_datetime("2020-01-02 01:02:03") -> 2020-01-02 01:02:03
```

## `to_string()`

### Syntax

`to_string(num)`

### Description

Converts a number to a string using the C++ printf function with the `g` specifier, which means it always produces the shortest output.

### Return type

`STRING`

### Parameters

| Parameter | Description | Data type |
| --- | --- | --- |
| `num` | The number to turn into a string | Number |

### Example

to_string(1000.1) -> "1000.1"
to_string(0.0000000001) -> "1E-10"
to_string(12300000000) -> "12300000000"  // Using an `INT` or `UINT` value returns the full number as a string without scientific notation
to_string(12300000000.0) -> "1.23e+10"  // Using a `DOUBLE` value returns scientific notation for large numbers
to_string(12300000000.0) -> "1.23e+10"  // Using a `FLOAT` value also returns scientific notation for large numbers

## `toBoolean()`

### Syntax

`toBoolean(input)`

### Description

This function converts a string into a boolean value (`true` or `false`).

* If the input is already a boolean, it returns the same value.
* If the input is a string equivalent of true or false (case-insensitive), it returns the corresponding boolean value.
* For other string inputs or parsing failures, it returns `NULL`.

### Return type

`BOOLEAN`

### Parameters

| Parameter | Description | Data type |
| --- | --- | --- |
| `input` | An expression that returns a boolean or string | String/Boolean |

### Example

toBoolean("true") -> true
toBoolean("false") -> false
toBoolean("invalid") -> null

## `toFloat()`

### Syntax

`toFloat(input)`

### Description

Converts an integer or string to a floating-point number.

* If the input is already a floating-point number, the function will return it unchanged.
* If the input is a valid number in string format (e.g., "14.5"), it converts the string to a float (e.g., 14.5).
* **Scientific notation** is supported. For example, "1.45e-06" is applicable.

### Return type

`FLOAT`

### Parameters

| Parameter | Description | Data type |
| --- | --- | --- |
| `input` | An expression that returns a numeric or string | String/Number |

### Example

toFloat(14) -> 14.0
toFloat("-3.5") -> -3.5
toFloat("1.45E-6") -> 1.45e-06
toFloat("invalid") -> NULL

## `toInteger()`

### Syntax

`toInteger(input)`

### Description

Converts a floating-point number or string to an integer.

* If the input is already an integer, it is returned unchanged.
* If the input is a valid number in string format (e.g., "42"), it converts the string to an integer (e.g., 42).
* If the input is a floating-point number, it truncates the decimal part (e.g., 14.7 becomes 14).

### Return type

`INTEGER`

### Parameters

| Parameter | Description | Data type |
| --- | --- | --- |
| `input` | An expression that returns a numeric or string | String/Number |

### Example

toInteger(14.7) -> 14
toInteger("-10") -> -10
toInteger("five") -> NULL
