Update json-functions.md

This commit is contained in:
Vladimir Goncharov 2021-10-23 19:04:29 +03:00 committed by GitHub
parent 900a359362
commit 1b2186b8ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -315,10 +315,10 @@ If the value does not exist, `0` will be returned.
Examples:
``` sql
SELECT JSON_EXISTS('$.hello', '{"hello":1}');
SELECT JSON_EXISTS('$.hello.world', '{"hello":{"world":1}}');
SELECT JSON_EXISTS('$.hello[*]', '{"hello":["world"]}');
SELECT JSON_EXISTS('$.hello[0]', '{"hello":["world"]}');
SELECT JSON_EXISTS('{"hello":1}', '$.hello');
SELECT JSON_EXISTS('{"hello":{"world":1}}', '$.hello.world');
SELECT JSON_EXISTS('{"hello":["world"]}', '$.hello[*]');
SELECT JSON_EXISTS('{"hello":["world"]}', '$.hello[0]');
```
!!! note "Note"
@ -326,17 +326,17 @@ SELECT JSON_EXISTS('$.hello[0]', '{"hello":["world"]}');
## JSON_QUERY(json, path) {#json-query}
Parses a JSON and extract a value.
Parses a JSON and extract a value as JSON array or JSON object.
If the value does not exist, an empty string will be returned.
Example:
``` sql
SELECT JSON_QUERY('$.hello', '{"hello":"world"}');
SELECT JSON_QUERY('$.array[*][0 to 2, 4]', '{"array":[[0, 1, 2, 3, 4, 5], [0, -1, -2, -3, -4, -5]]}');
SELECT JSON_QUERY('$.hello', '{"hello":2}');
SELECT toTypeName(JSON_QUERY('$.hello', '{"hello":2}'));
SELECT JSON_QUERY('{"hello":"world"}', '$.hello');
SELECT JSON_QUERY('{"array":[[0, 1, 2, 3, 4, 5], [0, -1, -2, -3, -4, -5]]}', '$.array[*][0 to 2, 4]');
SELECT JSON_QUERY('{"hello":2}', '$.hello');
SELECT toTypeName(JSON_QUERY('{"hello":2}', '$.hello'));
```
Result:
@ -352,17 +352,17 @@ String
## JSON_VALUE(json, path) {#json-value}
Parses a JSON and extract a value.
Parses a JSON and extract a value as JSON scalar.
If the value does not exist, an empty string will be returned.
Example:
``` sql
SELECT JSON_VALUE('$.hello', '{"hello":"world"}');
SELECT JSON_VALUE('$.array[*][0 to 2, 4]', '{"array":[[0, 1, 2, 3, 4, 5], [0, -1, -2, -3, -4, -5]]}');
SELECT JSON_VALUE('$.hello', '{"hello":2}');
SELECT toTypeName(JSON_VALUE('$.hello', '{"hello":2}'));
SELECT JSON_VALUE('{"hello":"world"}', '$.hello');
SELECT JSON_VALUE('{"array":[[0, 1, 2, 3, 4, 5], [0, -1, -2, -3, -4, -5]]}', '$.array[*][0 to 2, 4]');
SELECT JSON_VALUE('{"hello":2}', '$.hello');
SELECT toTypeName(JSON_VALUE('{"hello":2}', '$.hello'));
```
Result: