# **JQ()**

## **Function Description**

The `JQ()` function is used to parse and convert JSON data based on jq expressions. Unlike [`TRY_JQ()`](try_jq.md), `TRY_JQ()` supports returning null values when an error occurs, while `JQ()` directly throws an exception when an error occurs.

## **Grammar Structure**

```sql
select jq(jsonDoc, pathExpression);
```

## **Parameter definition**

| Parameters | Description |
| ---- | ---- |
| jsonDoc | This is a column or expression containing JSON data. |
| pathExpression | Used to specify how fields are extracted from JSON data |

## **Example**

```text
mysql> select jq('{"foo": 128}', '.foo');
+-----------------------------+
| jq({"foo": 128}, .foo) |
+-----------------------------+
| 128 |
+-----------------------------+
1 row in set (0.01 sec)

mysql> select jq(null, '.foo');
+---------------------+
| jq(null, .foo) |
+---------------------+
| NULL |
+---------------------+
1 row in set (0.00 sec)

mysql> select jq('{"id": "sample", "10": {"b": 42}}', '{(.id): .["10"].b}');
+------------------------------------------------------------------------------------------------------------------------------
| jq({"id": "sample", "10": {"b": 42}}, {(.id): .["10"].b}) |
+------------------------------------------------------------------------------------------------------------------------------
| {"sample":42} |
+------------------------------------------------------------------------------------------------------------------------------
1 row in set (0.00 sec)

mysql> select jq('[1, 2, 3]', '.foo & .bar');
ERROR 1105 (HY000): unexpected token "&"
```
