Files
Mårten HildellandClaude Opus 5.5 4fedb173a3 yaml: a # inside a plain scalar is not a comment (#30828)
YAML starts a comment only at a `#` that begins the line or follows white
space. strip_comments ended the line at any `#` outside a flow collection,
so `ref: net.arxml#Body` read as `net.arxml` and `- a#b` as `a`.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 02:04:58 +03:00
..

Description

yaml provides a pure-V YAML reader and writer for common configuration files. It supports nested mappings, sequences, flow-style collections, block scalars, tree access through yaml.Any, and generic struct encode/decode.

The generic encode/decode path delegates to the main json module so it matches existing JSON field behavior, including @[json: 'name'].

Usage

import yaml

struct Config {
	name    string
	enabled bool
	ports   []int
}

const config_text = '
name: app
enabled: true
ports:
  - 8080
  - 9090
'

fn main() {
	doc := yaml.parse_text(config_text)!
	assert doc.value('ports[1]').int() == 9090

	config := yaml.decode[Config](config_text)!
	assert config.name == 'app'
	assert yaml.encode(config).contains('"name": "app"')
}

File helpers

import yaml

struct Config {
	name string
}

fn main() {
	config := yaml.decode_file[Config]('config.yml')!
	yaml.encode_file('config.out.yml', config)!
}