Skip to content

YAML Adapter

The built-in YAML adapter uses js-yaml for YAML parsing and serialization.

Usage

morphql
from yaml to object
transform
  set name = name
  set age  = age
morphql
from object to yaml
transform clone
morphql
from yaml to yaml
transform
  set key   = key
  set value = value

Options

Options are forwarded directly to the underlying js-yaml functions.

Parse options (yaml.load)

OptionTypeDescription
schemastringYAML schema to use (default: DEFAULT_SCHEMA)
jsonbooleanAllow duplicate keys (last value wins, like JSON)

Serialize options (yaml.dump)

OptionTypeDefaultDescription
indentnumber2Number of spaces per indentation level
lineWidthnumber80Max line width before wrapping (-1 = no limit)
noRefsbooleanfalseDisable YAML anchors/aliases for duplicate objects
sortKeysbooleanfalseSort object keys alphabetically
flowLevelnumber-1Level at which to switch to flow style (-1 = block)

Examples

morphql
// 4-space indent, no line wrapping
from object to yaml(indent=4, lineWidth=-1)
transform clone
morphql
// Parse with duplicate keys allowed
from yaml(json=true) to object
transform clone

Released under the MIT License.