# typeof

[Read this page in HTML](https://www.scopedb.io/docs/reference/functions/semi-structured-data/typeof)

Reports the type of an `any` value or the distinct element types in an array.

## Syntax

```scopeql
typeof(<expr>)
```

## Arguments

| Argument | Type             | Description                                              |
| -------- | ---------------- | -------------------------------------------------------- |
| `<expr>` | `any` or `array` | Value to inspect. Cast other input types to `any` first. |

## Returns

For `any`, returns `string` naming the contained type. A NULL `any` value returns `'null'`.

For `array`, returns an `array` of distinct element type names, including `'null'` for NULL elements. Each type appears once. An empty array returns `[]`; a NULL array returns NULL.

## Examples

### Investigate inconsistent amount types

A producer may switch an amount from a number to text. Inspect the contained type before deciding how to cast it.

```scopeql
VALUES
    ('evt-17', {'amount': 49.0}), ('evt-42', {'amount': '79.00'}),
    ('evt-63', {'channel': 'web'})
SELECT $0 AS event_id, $1 AS payload
SELECT event_id, typeof(payload['amount']) AS amount_type
```

```text
+----------+-------------+
| event_id | amount_type |
+----------+-------------+
| evt-17   | float       |
| evt-42   | string      |
| evt-63   | null        |
+----------+-------------+
```

The missing `amount` field produces the type name `'null'`.

### Check the element types of an array

Inspect an item-ID array that unexpectedly contains a numeric ID.

```scopeql
SELECT typeof(['sku-1', 'sku-2', 42]) AS element_types
```

```text
+------------------+
| element_types    |
+------------------+
| ["int","string"] |
+------------------+
```

For an array input, `typeof` returns the distinct element types rather than the string `array`. Their order may vary.
