Skip to content

YAML (std::yaml)

std::yaml converts between YAML strings and Zolo maps. It is the natural choice for reading Kubernetes, GitHub Actions, docker-compose and similar configurations.

Parse

yaml.parse(string) converts YAML text into a Zolo map. Hyphen lists become arrays:

Scalars and a tag list from inline YAML.

01-parse.zolo
Playground
// Feature: yaml.parse — converts a YAML string into a map
// When to use: read YAML configurations (Kubernetes, GitHub Actions, etc.).

use std::yaml

let raw = "name: zolo\nversion: 0.1.0\ndebug: true"
let cfg = yaml.parse(raw)

print(cfg["name"])  // expected: zolo
print(cfg["version"])  // expected: 0.1.0
print(cfg["debug"])  // expected: true

// YAML also supports lists (with hyphens).
let raw2 = "tags:\n  - alpha\n  - beta\n  - gamma"
let cfg2 = yaml.parse(raw2)
print(cfg2["tags"][0])  // expected: alpha
print(cfg2["tags"][2])  // expected: gamma

Stringify

yaml.stringify(map) serialises a map to YAML text; parse(stringify(x)) is a lossless round-trip for scalar values:

Serialisation and round-trip of a simple configuration.

02-stringify.zolo
Playground
// Feature: yaml.stringify — serializes a map into a YAML string
// When to use: produce YAML configurations programmatically.

use std::yaml

let cfg = #{
  name: "zolo",
  version: "0.1.0",
  active: true,
}

let out = yaml.stringify(cfg)
print(out)

// expected (lines in `key: value` format):
// name: zolo
// version: 0.1.0
// active: true

// Round-trip returns to the same structure.
let back = yaml.parse(out)
print(back["name"])  // expected: zolo
print(back["active"])  // expected: true

Nested Structures

YAML sections become sub-maps; lists of maps (CI pipelines) are fully supported:

Hierarchical config with server/database and a pipeline with a list of steps.

03-nested.zolo
Playground
// Feature: yaml — nested structures and lists inside maps
// When to use: typical hierarchical configs (CI, Helm charts, docker-compose).

use std::yaml

let raw = "server:\n  host: localhost\n  port: 8080\ndatabase:\n  url: postgres://...\n  pool: 10"

let cfg = yaml.parse(raw)
print(cfg["server"]["host"])  // expected: localhost
print(cfg["server"]["port"])  // expected: 8080
print(cfg["database"]["pool"])  // expected: 10

// List of maps (typical in pipelines).
let raw2 = "steps:\n  - name: build\n  - name: test\n  - name: deploy"
let pipeline = yaml.parse(raw2)
print(pipeline["steps"][0]["name"])  // expected: build
print(pipeline["steps"][2]["name"])  // expected: deploy
enespt-br