yml.q

YAML: .yml.load reads YAML lines or a file into q values, .yml.dump writes a q value out as YAML lines.
  • author - drewsteele
  • link - https://github.com/drewsteele/qYaml Copyright (c) 2025 drewsteele, MIT License - the full licence text closes this file. use global variable for anchors would be nice to do this in a more functional way without globals but this was easiest

Entity Summary

EntitiesShort Description
.yml.dump[x]Write a q value as simplified block-style YAML: a dictionary becomes a mapping, a list or a table (one mapping per row) a sequence, :: an empty value, and a timestamp is written in ISO 8601.
.yml.load[yml]Parse YAML into q: a mapping is a dictionary, a sequence a list (a sequence of like mappings collapses to a table), and a scalar its natural q type.

Entity Details

.yml.dump[x]

Write a q value as simplified block-style YAML: a dictionary becomes a mapping, a list or a table (one mapping per row) a sequence, :: an empty value, and a timestamp is written in ISO 8601. A string holding a quote, a backslash, a tab, a newline or a digit is single-quoted; any other is written plain, so one that reads as another scalar (true, null, .inf) comes back from .yml.load as that value, not as a string.

Return: (any) the YAML as a list of strings, one per line - but a non-string atom answers its one line as a string
Parameters:
  • x - (any) the value to write

Examples

.yml.dump `name`tags!("peach";`q`kdb)

.yml.load[yml]

Parse YAML into q: a mapping is a dictionary, a sequence a list (a sequence of like mappings collapses to a table), and a scalar its natural q type. A null or empty value is ::, true/false are booleans, .nan/.inf are 0n/0w, 0x/0o numbers are longs, and an ISO timestamp is a kdb timestamp, shifted to UTC when it carries a zone offset. Anchors and aliases resolve; custom tags are ignored. Several documents, each opened by `---`, answer a list, less any document that is null as a whole; when only one is left it comes back alone, and when none is left, ().

Return: (any) the parsed document, or a list of documents
Parameters:
  • yml - (any) the YAML as a list of strings, one per line (enlist a single line), or a file symbol: `:config.yml
throws:
  • no - matching anchor found for alias an alias naming no earlier anchor
  • failed - to read yaml file a file symbol that cannot be read

Examples

.yml.load ("name: peach";"tags: [q, kdb]";"n: 3")