Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add json_extract #2268

Merged
merged 3 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs-2.0/2.quick-start/6.cheatsheet-for-ngql-command.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@
| list split(string a, string b) | 在子字符串 b 处拆分字符串 a,返回一个字符串列表。 |
| concat() | `concat()`函数至少需要两个或以上字符串参数,并将所有参数连接成一个字符串。<br>语法:`concat(string1,string2,...)` |
| concat_ws() | `concat_ws()`函数将两个或以上字符串参数与预定义的分隔符(separator)相连接。 |
| extract() | `extract()` 从指定字符串中提取符合正则表达式的子字符串。|
| json_extract() |`json_extract()` 将指定 JSON 字符串转换为 map 类型。|


* [日期时间函数](../3.ngql-guide/6.functions-and-expressions/3.date-and-time.md)

Expand Down
25 changes: 25 additions & 0 deletions docs-2.0/3.ngql-guide/6.functions-and-expressions/2.string.md
Original file line number Diff line number Diff line change
Expand Up @@ -525,3 +525,28 @@ nebula> MATCH (a:player)-[b:serve]-(c:team{name: "Lakers"}) \
| [] |
+--------+
```

## json_extract() 函数

json_extract() 将指定 JSON 字符串转换为 map 类型。

语法:`extract(<string>)`

- `string`:指定字符串,为 JSON 格式。
- 返回类型:map。

!!! caution

- 目前仅支持 Bool、Double、Int、String 和 NULL 类型数据。
- 仅支持深度为 1 的 Map 嵌套,如果嵌套深度为 2 及以上,嵌套项保留为空。

示例:

```ngql
nebula> YIELD json_extract('{"a": 1, "b": {}, "c": {"d": true}}') AS result;
+-----------------------------+
| result |
+-----------------------------+
| {a: 1, b: {}, c: {d: true}} |
+-----------------------------+
```