# 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
}
```
