> ## Documentation Index
> Fetch the complete documentation index at: /documents/llms.txt
> Use this file to discover all available pages before exploring further.

# json_object

> Converts one or more key-value pairs to a JSON object that consists of the key-value pairs.

Converts one or more key-value pairs to a JSON object that consists of the key-value pairs. The key-value pairs are sorted by key in dictionary order.

**Tip**

All of the JSON functions and operators are listed in the navigation and on the [overview page](/documents/4.2/sql-reference/sql-functions/json-functions/overview-of-json-functions-and-operators.md)

Accelerate your queries with [generated columns](/documents/4.2/sql-reference/sql-statements/generated_columns.md)

## Syntax

```Haskell theme={null}
json_object(key, value, ...)
```

## Parameters

* `key`: a key in the JSON object. Only the VARCHAR data type is supported.

* `value`: a value in the JSON object. Only `NULL` values and the following data types are supported: STRING, VARCHAR, CHAR, JSON, TINYINT, SMALLINT, INT, BIGINT, LARGEINT, DOUBLE, FLOAT, and BOOLEAN.

## Return value

Returns a JSON object.

> If the total number of keys and values is an odd number, the JSON\_OBJECT function fills `NULL` in the last field.

## Examples

Example 1: Construct a JSON object that consists of values of different data types.

```plaintext theme={null}
mysql> SELECT json_object('name', 'starrocks', 'active', true, 'published', 2020);

       -> {"active": true, "name": "starrocks", "published": 2020}            
```

Example 2: Construct a JSON object by using nested JSON\_OBJECT functions.

```plaintext theme={null}
mysql> SELECT json_object('k1', 1, 'k2', json_object('k2', 2), 'k3', json_array(4, 5));

       -> {"k1": 1, "k2": {"k2": 2}, "k3": [4, 5]} 
```

Example 3: Construct an empty JSON object.

```plaintext theme={null}
mysql> SELECT json_object();

       -> {}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.