Function | Syntax | Description |
json_array_contains(x, value) | Determines whether a JSON array contains a given value. | |
json_array_get(x, index) | Returns the element with the specified index in a given JSON array. | |
json_array_length(x) | Returns the number of elements in a given JSON array. If `x` is not a JSON array, `null` will be returned. | |
json_extract(x, json_path) | Extracts a set of JSON values (array or object) from a JSON object or array. | |
json_extract_scalar(x, json_path) | Extracts a set of scalar values (strings, integers, or Boolean values) from a JSON object or array. Similar to the `json_extract` function. | |
json_format(x) | Converts a JSON value into a string value. | |
json_parse(x) | Converts a string value into a JSON value. | |
json_size(x, json_path) | Calculates the number of elements in a JSON object or array. |
json_array_contains
function is used to determine whether a JSON array contains a specified value.json_array_contains(x, value)
Parameter | Description |
x | The parameter value is a JSON array. |
value | Value. |
* | SELECT json_array_contains('[1, 2, 3]', 2)
TRUE
json_array_get
function is used to get the element with a specified index in a JSON array.json_array_get(x, index)
Parameter | Description |
x | The parameter value is a JSON array. |
index | JSON subscript (index), starting from 0. |
* | SELECT json_array_get('["a", [3, 9], "c"]', 1)
[3,9]
json_array_length
function is used to calculate the number of elements in a JSON array. If x
is not a JSON array, null
will be returned.json_array_length(x)
Parameter | Description |
x | The parameter value is a JSON array. |
apple.message:[{"traceName":"StoreMonitor"},{"topicName":"persistent://apache/pulsar/test-partition-17"},{"producerName":"pulsar-mini-338-36"},{"localAddr":"pulsar://pulsar-mini-broker-5.pulsar-mini-broker.pulsar.svc.cluster.local:6650"},{"sequenceId":826},{"storeTime":1635905306062},{"messageId":"19422-24519"},{"status":"SUCCESS"}]
* | SELECT json_array_length(apple.message)
8
json_extract
function is used to extract a set of JSON values (array or object) from a JSON object or array.json_extract(x, json_path)
Parameter | Description |
x | The parameter value is a JSON object or array. |
json_path | Note: JSON syntax requiring array element traversal is not supported, such as the following: $.store.book[*].author , $..book[(@.length-1)] , $..book[?(@.price<10)] . |
apple.instant:{"epochSecond":1635905306,"nanoOfSecond":63001000}
* | SELECT json_extract(apple.instant, '$.epochSecond')
1635905306
json_extract_scalar
function is used to extract a set of scalar values (strings, integers, or Boolean values) from a JSON object or array.json_extract_scalar(x, json_path)
Parameter | Description |
x | The parameter value is a JSON array. |
json_path | Note: JSON syntax requiring array element traversal is not supported, such as the following: $.store.book[*].author , $..book[(@.length-1)] , $..book[?(@.price<10)] . |
apple.instant:{"epochSecond":1635905306,"nanoOfSecond":63001000}
* | SELECT sum(cast(json_extract_scalar(apple.instant,'$.epochSecond') AS bigint) )
1635905306
json_format
function is used to convert a JSON value into a string value.json_format(x)
Parameter | Description |
x | The parameter value is of JSON type. |
* | SELECT json_format(json_parse('[1, 2, 3]'))
[1, 2, 3]
json_parse
function is used to convert a string value into a JSON value and determine whether it complies with the JSON format.json_parse(x)
Parameter | Description |
x | The parameter value is a string. |
* | SELECT json_parse('[1, 2, 3]')
[1, 2, 3]
json_size
function is used to calculate the number of elements in a JSON object or array.json_size(x, json_path)
Parameter | Description |
x | The parameter value is a JSON object or array. |
json_path | JSON path, in the format of $.store.book[0].title . |
* | SELECT json_size(json_parse('[1, 2, 3]'),'$')
3
Apakah halaman ini membantu?