

# JSON functions and operators in DuckDB

Use JSON functions and operators to parse JSON text, read values from JSON documents, and test what a document contains. You can also build and merge JSON values, and convert JSON to SQL types such as `STRUCT` and lists.

DuckDB stores JSON in the `JSON` type. The JSON functions also accept JSON text as a `VARCHAR` value and parse it for you, so `json_extract('{"a": 1}', '$.a')` works without a cast. If the text is not valid JSON, the query fails. To test text before you parse it, use the [`json_valid` function](duckdb-functions-json-inspection.md#athena-duckdb-functions-json-json-valid).

A SQL `NULL` and the JSON value `null` are not the same. Functions that return `JSON`, such as `json_extract` and its operator form `->`, return the JSON value `null` for a member whose value is `null`. For that value, `IS NULL` is `false`. Functions that return text, such as the `->>` operator, return SQL `NULL` instead. Both kinds of function return SQL `NULL` when the member does not exist. To test the result of the `->` operator, put the expression in parentheses, as in `({{json}} -> '$.a') IS NULL`.

Functions that read part of a document take a JSON path, such as `'$.customer.name'` or `'$.items[0]'`. For more information about the path syntax, see [JSON paths](duckdb-functions-json-extraction.md#athena-duckdb-functions-json-json-paths).

**Topics**
+ [Extraction](duckdb-functions-json-extraction.md)
+ [Inspection](duckdb-functions-json-inspection.md)
+ [Format and parse](duckdb-functions-json-formatting-and-parsing.md)
+ [Creation](duckdb-functions-json-creation.md)
+ [Conversion](duckdb-functions-json-conversion.md)
+ [Modification](duckdb-functions-json-modification.md)

The following table lists the JSON functions and operators, with a link to the description of each one.


| Function or operator | Description | 
| --- | --- | 
| [->>](duckdb-functions-json-extraction.md#athena-duckdb-functions-json-extract-string-operator) | Extracts a value from JSON at a path or an array position and returns it as text. | 
| from\_json | Alias of [json\_transform](duckdb-functions-json-conversion.md#athena-duckdb-functions-json-json-transform). | 
| from\_json\_strict | Alias of [json\_transform\_strict](duckdb-functions-json-conversion.md#athena-duckdb-functions-json-json-transform-strict). | 
| [json](duckdb-functions-json-formatting-and-parsing.md#athena-duckdb-functions-json-json) | Parses text as JSON and returns it in compact form. | 
| [JSON paths](duckdb-functions-json-extraction.md#athena-duckdb-functions-json-json-paths) | Describes the path syntax that JSON functions and operators use to select part of a JSON value. | 
| [json\_array](duckdb-functions-json-creation.md#athena-duckdb-functions-json-json-array) | Builds a JSON array from a list of values. | 
| [json\_array\_length](duckdb-functions-json-inspection.md#athena-duckdb-functions-json-json-array-length) | Returns the number of elements in a JSON array. | 
| [json\_contains](duckdb-functions-json-inspection.md#athena-duckdb-functions-json-json-contains) | Tests whether a JSON value contains another JSON value. | 
| [json\_deep\_merge](duckdb-functions-json-modification.md#athena-duckdb-functions-json-json-deep-merge) | Merges JSON objects at every depth, with later values taking precedence. | 
| [json\_deserialize\_sql](duckdb-functions-json-formatting-and-parsing.md#athena-duckdb-functions-json-json-deserialize-sql) | Converts the JSON form of a parsed `SELECT` statement back to SQL text. | 
| [json\_each](duckdb-functions-json-extraction.md#athena-duckdb-functions-json-json-each) | Returns one row for each element of a JSON array or each member of a JSON object. | 
| [json\_exists](duckdb-functions-json-inspection.md#athena-duckdb-functions-json-json-exists) | Tests whether a path selects a value in a JSON document. | 
| [json\_extract](duckdb-functions-json-extraction.md#athena-duckdb-functions-json-json-extract) | Extracts a value from JSON at a path or an array position and returns it as JSON. | 
| json\_extract\_path | Alias of [json\_extract](duckdb-functions-json-extraction.md#athena-duckdb-functions-json-json-extract). | 
| json\_extract\_path\_text | Alias of [json\_extract\_string](duckdb-functions-json-extraction.md#athena-duckdb-functions-json-json-extract-string). | 
| [json\_extract\_string](duckdb-functions-json-extraction.md#athena-duckdb-functions-json-json-extract-string) | Returns the value at a path in a JSON document as text. | 
| [json\_group\_array](duckdb-functions-json-creation.md#athena-duckdb-functions-json-json-group-array) | Aggregates the values in a group into a JSON array. | 
| [json\_group\_object](duckdb-functions-json-creation.md#athena-duckdb-functions-json-json-group-object) | Aggregates key and value pairs in a group into a JSON object. | 
| [json\_group\_structure](duckdb-functions-json-conversion.md#athena-duckdb-functions-json-json-group-structure) | Describes the keys and value types found across the JSON values in a group. | 
| [json\_insert](duckdb-functions-json-modification.md#athena-duckdb-functions-json-json-insert) | Adds a value to a JSON document at a path where no value exists yet. | 
| [json\_keys](duckdb-functions-json-inspection.md#athena-duckdb-functions-json-json-keys) | Lists the key names of a JSON object. | 
| [json\_merge\_patch](duckdb-functions-json-modification.md#athena-duckdb-functions-json-json-merge-patch) | Merges JSON documents by applying each later document as a JSON merge patch. | 
| [json\_merge\_patch\_diff](duckdb-functions-json-modification.md#athena-duckdb-functions-json-json-merge-patch-diff) | Returns the JSON merge patch that turns one JSON document into another. | 
| [json\_normalize](duckdb-functions-json-formatting-and-parsing.md#athena-duckdb-functions-json-json-normalize) | Returns a JSON document as compact text with sorted keys. | 
| [json\_object](duckdb-functions-json-creation.md#athena-duckdb-functions-json-json-object) | Returns a JSON object whose members come from pairs of key and value arguments. | 
| [json\_pretty](duckdb-functions-json-formatting-and-parsing.md#athena-duckdb-functions-json-json-pretty) | Formats a JSON document on several indented lines for reading. | 
| json\_quote | Alias of [to\_json](duckdb-functions-json-creation.md#athena-duckdb-functions-json-to-json). | 
| [json\_remove](duckdb-functions-json-modification.md#athena-duckdb-functions-json-json-remove) | Removes the value at a path from a JSON document. | 
| [json\_replace](duckdb-functions-json-modification.md#athena-duckdb-functions-json-json-replace) | Replaces a value that already exists at a path in a JSON document. | 
| [json\_serialize\_sql](duckdb-functions-json-formatting-and-parsing.md#athena-duckdb-functions-json-json-serialize-sql) | Parses SQL `SELECT` text and returns its parse tree as JSON. | 
| [json\_set](duckdb-functions-json-modification.md#athena-duckdb-functions-json-json-set) | Writes a value at a JSON path, replacing the value that is there or adding it. | 
| [json\_strip\_nulls](duckdb-functions-json-modification.md#athena-duckdb-functions-json-json-strip-nulls) | Removes the object members whose value is JSON `null`, at every level of a JSON value. | 
| [json\_structure](duckdb-functions-json-conversion.md#athena-duckdb-functions-json-json-structure) | Returns the structure of a JSON value, with the type of each member and element. | 
| [json\_transform](duckdb-functions-json-conversion.md#athena-duckdb-functions-json-json-transform) | Converts JSON to a SQL value of the type that a structure describes, and returns `NULL` for values that are missing or do not convert. | 
| [json\_transform\_strict](duckdb-functions-json-conversion.md#athena-duckdb-functions-json-json-transform-strict) | Converts JSON to a SQL value of the type that a structure describes, and fails when a value is missing or does not convert. | 
| [json\_tree](duckdb-functions-json-extraction.md#athena-duckdb-functions-json-json-tree) | Returns one row for each value in a JSON document, including the values nested at every level. | 
| [json\_type](duckdb-functions-json-inspection.md#athena-duckdb-functions-json-json-type) | Returns the type of a JSON value, or of the value at a JSON path. | 
| [json\_valid](duckdb-functions-json-inspection.md#athena-duckdb-functions-json-json-valid) | Tests whether a string is valid JSON text. | 
| [json\_value](duckdb-functions-json-extraction.md#athena-duckdb-functions-json-json-value) | Returns the scalar value at a JSON path as JSON text. | 
| [row\_to\_json](duckdb-functions-json-creation.md#athena-duckdb-functions-json-row-to-json) | Converts a struct, such as a whole row, to a JSON object. | 
| [to\_json](duckdb-functions-json-creation.md#athena-duckdb-functions-json-to-json) | Converts a value of any type to JSON. | 