apoc.convert.fromYaml
函数 Apoc 扩展
apoc.convert.fromYaml(value, $config) - 将 YAML 字符串反序列化为 Neo4j 值
配置参数
该过程支持以下配置参数
| 名称 (name) | type | 默认 | description(描述) |
|---|---|---|---|
disable |
字符串列表 |
空列表 |
用于禁用底层所用库中默认启用的一个或多个配置。请参阅此处。 |
enable |
字符串列表 |
空列表 |
用于启用底层所用库的一个或多个配置。请参阅此处。 |
mapping(映射) |
字符串映射 |
空映射 |
用于映射复杂的 YAML。 为了读取 FasterXML Jackson 不支持的复杂类型(如 Long 等),我们可以使用 mapping 配置将其转换为所需的数据类型。例如,如果我们有一个 YAML |
使用示例
我们可以将任何 YAML 字符串转换为节点/关系的列表或映射
将 YAML 字符串转换为映射
RETURN apoc.convert.fromYaml("a: 42
b: foo") AS value
| 值 |
|---|
|
使用自定义映射将 YAML 字符串转换为映射
RETURN apoc.convert.fromYaml("a: 42
b: foo", {mapping: {a: "Long"} }) AS value
| 值 |
|---|
|
使用自定义特性将 YAML 字符串转换为映射
RETURN apoc.convert.fromYaml("a: 42
b: foo", {enable: ['MINIMIZE_QUOTES'], disable: ['WRITE_DOC_START_MARKER']}) AS value
| 值 |
|---|
|
将 YAML 字符串转换为列表
RETURN apoc.convert.fromYaml("---
- 1
- 2
- 3") as value
| 值 |
|---|
|
将 YAML 字符串转换为列表并将类型映射为 Long
RETURN apoc.convert.fromYaml("---
- 1
- 2
- 3",
{mapping: {_: "Long"}}) as value
| 值 |
|---|
|
从 YAML 字符串转换为映射
RETURN apoc.convert.fromYaml("---
a: 42
b: \"foo\"
c:
- 1
- 2
- 3") as value
| 值 |
|---|
|
从 YAML 字符串转换为节点
RETURN apoc.convert.fromYaml("---
id: \"<elementID>\"
type: \"node\"
labels:
- \"Test\"
properties:
foo: 7") as value
| 值 |
|---|
|
从带有空值的 YAML 字符串转换为映射
RETURN apoc.convert.fromYaml("---
a: null
b: \"myString\"
c:
- 1
- \"2\"
- null") as value
| 值 |
|---|
|
从 YAML 字符串转换为节点映射
RETURN apoc.convert.fromYaml("---
one:
id: \"8d3a6b87-39ad-4482-9ce7-5684fe79fc57\"
type: \"node\"
labels:
- \"Test\"
properties:
foo: 7
two:
id: \"3fc16aeb-629f-4181-97d2-a25b22b28b75\"
type: \"node\"
labels:
- \"Test\"
properties:
bar: 9
") as value
| 值 |
|---|
|
从 YAML 字符串转换为关系
RETURN apoc.convert.fromYaml("---
id: \"94996be1-7200-48c2-81e8-479f28bba84d\"
type: \"relationship\"
label: \"KNOWS\"
start:
id: \"8d3a6b87-39ad-4482-9ce7-5684fe79fc57\"
type: \"node\"
labels:
- \"User\"
properties:
name: \"Adam\"
end:
id: \"3fc16aeb-629f-4181-97d2-a25b22b28b75\"
type: \"node\"
labels:
- \"User\"
properties:
name: \"Jim\"
age: 42
properties:
bffSince: \"P5M1DT12H\"
since: 1993.1
") as value
| 值 |
|---|
|