# JSON Functions

<mark style="color:purple;">**JSON\_VALUE  (**</mark>**&#x20;\<json\_string>, \<json\_path>&#x20;**<mark style="color:purple;">**) / JSON\_EXTRACT  (**</mark>**&#x20;\<json\_string>, \<json\_path>&#x20;**<mark style="color:purple;">**)**</mark>

Retrieves a JSON value corresponding to the given json path. If the json path is not present then `None` is returned.

**Note**: Given JSON string should be valid

<pre class="language-sql"><code class="lang-sql"><strong>> SELECT 
</strong><strong>JSON_VALUE('{"fruits": [{"apples": 5, "oranges": 10}, 
</strong><strong>{"apples": 2, "oranges": 4}], 
</strong><strong>"vegetables": [{"lettuce": 7, "kale": 8}]}','$.fruits') AS string_array
</strong>[{"apples":5,"oranges":10},{"apples":2,"oranges":4}]

> SELECT 
JSON_VALUE('{"fruits": [{"apples": 5, "oranges": 10}, 
{"apples": 2, "oranges": 4}], 
"vegetables": [{"lettuce": 7, "kale": 8}]}','$.fruits[1].oranges') 
AS string_array
10
</code></pre>

* Indexing starts from 1 (i.e., the first element is at index 1, the second is at index 2, and so on).
* If you provide an index that is 0 or less, it wraps around and starts counting from the end of the array. For example, an index of 0 refers to the last element in the array, -1 to the second last etc.

<mark style="color:purple;">**TO\_JSON  (**</mark>**&#x20;\<expr> )**

Converts a STRUCT value to a string containing the JSON representation of the value.

```sql
> select (to_json(named_struct('1','xyz','2',123)));
{
  "1": "xyz",
  "2": 123
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.e6data.com/product-documentation/sql-command-reference/json-functions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
