Skip to main content

nest

nest is a DTL operation that groups sibling keys under a new wrapper mapping.

Use it when flat fields should become a nested object.

YOp

- nest:
path: config
keys: [host, port]
under: database

Parameters

ParameterTypeRequiredDescription
pathstringyesPath to the parent mapping that contains the sibling keys.
keyssequence of stringsyesExisting sibling keys to move under the wrapper.
understringyesNew wrapper key name.

Behavior

  • Requires path to exist and be a mapping.
  • Requires every listed key to exist as a sibling in that mapping.
  • Requires the wrapper key to be absent.
  • Moves the listed keys under the new wrapper.

Errors

ErrorMeaning
PATH_NOT_FOUNDParent path does not exist.
NOT_A_MAPPINGParent is not a mapping.
NOT_SIBLINGSOne or more listed keys are not siblings in the parent.
ALREADY_EXISTSWrapper key already exists.

Example

yops:
- nest:
path: config
keys: [host, port]
under: database

Input:

config:
host: localhost
port: 5432
debug: true

Output:

config:
database:
host: localhost
port: 5432
debug: true