apoc.convert.toYaml

Function Apoc Extended

apoc.convert.toYaml(value, $config) - Serializes the given value to a YAML string

Signature

apoc.convert.toYaml(value :: ANY, config = {} :: MAP) :: STRING

Input parameters

Name Type Default

value

ANY

null

config

MAP

{}

Config parameters

The procedure support the following config parameters:

Table 1. Config parameters
name type default description

disable

list of strings

empty list

To disable one or more configurations, enabled by default, of the library used under the hood. See here.

enable

list of strings

empty list

To enable one or more configurations of the library used under the hood. See here.

Usage Examples

We can convert any value, including list/map of nodes/rels/paths

Convert map to YAML
RETURN apoc.convert.toYaml({a:42,b:"foo"}) AS value
Table 2. Results
value
---
a: 42
b: "foo"
c:
- 1
- 2
- 3
Convert map to YAML, with custom feature
RETURN apoc.convert.toYaml({a:42,b:"foo"},
    {enable: ['MINIMIZE_QUOTES'], disable: ['WRITE_DOC_START_MARKER']}
) AS value
Table 3. Results
value
a: 42
b: "foo"
Convert node to YAML
RETURN apoc.convert.toYaml({a:42,b:"foo"},
    {enable: ['MINIMIZE_QUOTES'], disable: ['WRITE_DOC_START_MARKER']}
) AS value
Table 4. Results
value
---
id: "<elementID>"
type: "node"
labels:
- "Test"
properties:
  foo: 7
Convert map of nodes to YAML
CREATE (a:Test {foo: 7}), (b:Test {bar: 9})
RETURN apoc.convert.toYaml({one: a, two: b}) AS value, elementId(a) AS idA, elementId(b) AS idB
Table 5. Results
value
---
one:
  id: "<elementID>"
  type: "node"
  labels:
  - "Test"
  properties:
    foo: 7
two:
  id: "<elementID>"
  type: "node"
  labels:
  - "Test"
  properties:
    bar: 9
Convert path to YAML
CREATE p=(a:Test {foo: 7})-[r1:TEST]->(b:Baz {a:'b'})<-[r2:TEST_2 {aa:'bb'}]-(c:Bar {one:'www', two:2, three: localdatetime('2020-01-01')})
RETURN apoc.convert.toYaml(p) AS value, elementId(a) AS idTest, elementId(b) AS idBaz, elementId(c) AS idBar, elementId(r1) AS idTEST, elementId(r2) AS idTEST_2
Table 6. Results
value
---
- id: "<elementID>"
  type: "node"
  properties:
    foo: 7
  labels:
  - "Test"
- start:
    id: "<elementID>"
    type: "node"
    properties:
      foo: 7
    labels:
    - "Test"
  end:
    id: "<elementID>"
    type: "node"
    properties:
      a: "b"
    labels:
    - "Baz"
  id: "<elementID>"
  label: "TEST"
  type: "relationship"
- id: "%2$s"
  type: "node"
  properties:
    a: "b"
  labels:
  - "Baz"
- start:
    id: "<elementID>"
    type: "node"
    properties:
      one: "www"
      three: "2020-01-01T00:00"
      two: 2
    labels:
    - "Bar"
  end:
    id: "<elementID>"
    type: "node"
    properties:
      a: "b"
    labels:
    - "Baz"
  id: "<elementID>"
  label: "TEST_2"
  type: "relationship"
  properties:
    aa: "bb"
- id: "%3$s"
  type: "node"
# ...