JSON Functions Operating on JSON Data
These JSON functions provide means to process JSON documents stored in nativeJSON columns. This should be preferred over storing JSON data in TEXT columns.
- These operators extract a field from a JSON value, returing another JSON value:
- Dot Operator (
.) - Subscript Operator (
[])
- Dot Operator (
- These functions convert a JSON value to a SQL value:
- These functions convert a SQL value to a JSON value:
JSON Functions Operating on TEXT Data
These JSON functions provide means to process JSON documents stored inTEXT columns.
There are three types of JSON functions for extracting values:
- These functions extract part of the document, but preserve the original data in the result:
- These functions convert a JSON value to a SQL value:
- This function extracts a JSON value and converts it to a SQL value, combining the functionalities of the previous two types of functions:
JSON_POINTER_EXTRACT to extract a value from a JSON document and JSON_VALUE to convert it into a SQL value:
val1 as a SQL TEXT value, rather than the original JSON value "val1" with the double quotes.
The JSON_FORMAT function can be used to format JSON documents, including pretty-printing and minifying documents.
Currently, JSON functions support only JSON pointer expressions, which provide a method for accessing specific elements within a JSON document.
For convenience, the following aliases are available for JSON functions that use JSON pointer expressions:
JSON_POINTER_EXTRACTis an alias forJSON_EXTRACTwith thepath_syntaxparameter set to'JSONPointer'.JSON_POINTER_EXTRACT_ARRAYis an alias forJSON_EXTRACT_ARRAYwith thepath_syntaxparameter set to'JSONPointer'.
JSON pointer expression syntax
The placeholder<json_pointer_expression> indicates where you should use a JSON pointer, which allows access to specific elements in a JSON document. For a formal specification, see RFC6901.
A JSON pointer begins with a forward slash (/), indicating the root of the JSON document, followed by a sequence of property (key) names or zero-based ordinal numbers separated by slashes. Property names identify specific keys, while index numbers specify the Nth element in an array or object.
The tilde (~) and forward slash (/) characters have special meanings and need to be escaped as follows:
- To specify a literal tilde (
~), use~0. - To specify a literal forward slash (
/), use~1.
JSON common example
The following JSON document, represented by the<json_common_example> placeholder, is used as a basis for all JSON function examples in this reference.