yamlSerialize

Serializes a CFML value (struct, array, or scalar) to a YAML string and returns it. When a file path is supplied, the YAML is also written to that file. Struct keys beginning with two underscores are skipped, mirroring serializeJSON. The charset argument is accepted but ignored (output is UTF-8).

yamlSerialize(data [, filePath, charset]) → returns string

This function requires RustCFML.  Not supported on Lucee, Adobe ColdFusion, etc.

Argument Reference

data any
Required

The CFML value to serialize to YAML.

filePath string

Optional file path to also write the YAML string to.

charset string
Default: utf8

Character encoding (accepted for compatibility; output is always UTF-8).

Examples
Sample code invoking the yamlSerialize function

Returns the YAML string.

data = { name = "Alex", age = 30 };
yaml = yamlSerialize(data);

Expected Result: name: Alex age: 30

The YAML string is returned and also written to the file.

yaml = yamlSerialize(data, expandPath("./config.yaml"));

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub