Skip to main content

split

split is a DTL operation that distributes keys from one mapping into new child mappings.

Use it when one mapping contains several groups of fields that should become separate named children.

YOp

- split:
path: config
into:
database: [host, port]
cache: [redis_url, ttl]

Parameters

ParameterTypeRequiredDescription
pathstringyesPath to the mapping to split.
intomappingyesMapping from new child key names to lists of existing source keys.

Behavior

  • Requires path to exist and be a mapping.
  • Requires every referenced source key to exist.
  • Moves referenced keys into the requested child mappings.
  • Leaves unlisted keys on the original mapping.
  • Rejects assigning the same source key to more than one child.

Errors

ErrorMeaning
PATH_NOT_FOUNDTarget path or a referenced source key does not exist.
NOT_A_MAPPINGTarget is not a mapping.
ALREADY_EXISTSA child group name collides with an unmoved key.
INVALID_OPA source key is assigned to multiple groups.

Example

yops:
- split:
path: config
into:
db: [host, port]
log: [level]

Input:

config:
host: localhost
port: 5432
level: debug

Output:

config:
db:
host: localhost
port: 5432
log:
level: debug