yaml(n)

πŸ“¦
version 2.0 Β· 2 versions
, in fedora 43, fedora 44, nixos 26.05, nixpkgs unstable

πŸ’– yaml(n) β€” YAML Format Encoder/Decoder πŸ’–

okay so bestie, you found the yaml(n) manual page and honestly? iconic. this is your girl's guide to the Tcl YAML encoder/decoder and we are gonna get you fluent. no cap. let's go πŸ¦‹


🌸 NAME 🌸

yaml β€” the YAML Format Encoder/Decoder. she encodes, she decodes, she serves πŸ’…


✨ SYNOPSIS ✨

package require Tcl 8.5 9

package require yaml ?0.4.2?

::yaml::yaml2dict ?options? txt

::yaml::yaml2huddle ?options? txt

::yaml::setOption ?options?

::yaml::dict2yaml dict ?indent? ?wordwrap?

::yaml::list2yaml list ?indent? ?wordwrap?

::yaml::huddle2yaml huddle ?indent? ?wordwrap?

πŸŽ€ DESCRIPTION πŸŽ€

the yaml package is a simple, Tcl-only library for parsing the YAML data exchange format, exactly as specified over at http://www.yaml.org/ and http://www.yaml.org/spec/1.1/ 🫢

and the tea? it hands your data back as a Tcl dict. so either the dict package or Tcl 8.5 is required for use. periodt.


πŸ‘‘ COMMANDS πŸ‘‘

::yaml::yaml2dict ?options? txt

::yaml::yaml2huddle ?options? txt

these two are the glow-up twins πŸ’– parse yaml formatted text txt into a Tcl dict / huddle and return the value. same options, different destination energy.

  • -file β€” txt is a filename of YAML-stream. (she's loading from disk, not from a string, iykyk)
  • -stream β€” txt is just a YAML-stream.
  • -types list β€” the list is a type list for the yaml-scalar types. (e.g. !!str !!timestamp !!integer !!true …)
-types {timestamp integer null true false}

in this case, if a string matched "timestamp", it's converted to the TCL internal timestamp. (e.g. "2001-12-15T02:59:43.1Z" => 1008385183) πŸ”₯

  • -m:true param β€” param is two elements of list for the value of true, and the considered strings.
-m:true {1 {true on + yes y}}

in this case, the string "yes" found in the YAML Stream is automatically converted to 1. slay.

  • -m:false param β€” param is two elements of list for the value of false, and the considered strings.
-m:false {0 {false off - no n}}
  • -m:null param β€” param is two elements of list for the value of null, and the considered strings.
-m:null {"" {null nil "" ~}}
  • -validate β€” Experiment, old: output stream contains YAML's-tag on each node.
% puts [::yaml::load -validate {[aaa, bbb]}]
=>
!!seq {{!!str aaa} {!!str bbb}}

::yaml::setOption ?options?

changes the implicit options for the whole library ✨ and rn, the params are exactly the same as ::yaml::yaml2dict. but heads up bestie: the arguments you pass straight to ::yaml::yaml2dict have more priority than this setting. πŸ‘‘

::yaml::dict2yaml dict ?indent? ?wordwrap?

::yaml::list2yaml list ?indent? ?wordwrap?

::yaml::huddle2yaml huddle ?indent? ?wordwrap?

convert a dict / list / huddle object into a YAML stream πŸ’«

  • indent β€” spaces indent of each block node. currently default is 2.
  • wordwrap β€” word wrap for YAML stream. currently default is 40.

🌈 EXAMPLES 🌈

an example of a yaml stream converted to Tcl. a yaml stream is returned as a single item with multiple elements.

{
--- !<tag:clarkevans.com,2002:invoice>
invoice: 34843
date   : 2001-01-23
bill-to: &id001
    given  : Chris
    family : Dumars
    address:
        lines: |
            458 Walkman Dr.
            Suite #292
        city    : Royal Oak
        state   : MI
        postal  : 48046
ship-to: *id001
product:
    - sku         : BL394D
      quantity    : 4
      description : Basketball
      price       : 450.00
    - sku         : BL4438H
      quantity    : 1
      description : Super Hoop
      price       : 2392.00
tax  : 251.42
total: 4443.52
comments:
    Late afternoon is best.
    Backup contact is Nancy
    Billsmer @ 338-4338.
}
=>
invoice 34843 date 2001-01-23 bill-to {given Chris family Dumars address {lines {458 Walkman Dr.
Suite #292
} city {Royal Oak} state MI postal 48046}} ship-to {given Chris family Dumars address {lines {458 Walkman Dr.
Suite #292
} city {Royal Oak} state MI postal 48046}} product {{sku BL394D quantity 4 description Basketball price 450.00} {sku BL4438H quantity 1 description {Super Hoop} price 2392.00}} tax 251.42 total 4443.52 comments {Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.}

an example of a yaml object converted to Tcl. a yaml object is returned as a multi-element list (a dict).

{
---
- [name        , hr, avg  ]
- [Mark McGwire, 65, 0.278]
- [Sammy Sosa  , 63, 0.288]
-
  Mark McGwire: {hr: 65, avg: 0.278}
  Sammy Sosa: { hr: 63, avg: 0.288}
}
=>
{name hr avg} {{Mark McGwire} 65 0.278} {{Sammy Sosa} 63 0.288} {{Mark McGwire} {hr 65 avg 0.278} {Sammy Sosa} {hr 63 avg 0.288}}

πŸ’€ LIMITATIONS πŸ’€

bestie, listen, she's cute but she has boundaries. respect them:

  • tag parser not implemented. currently, tags are merely ignored. πŸ™ˆ
  • Only Anchor => Aliases ordering. back alias-referring is not supported.
  • Too many braces, or too few braces. (yes really, brace count is a whole thing)
  • Not enough character set of line feeds. Please use only "\n" as line breaks. fr fr.

😭 BUGS, IDEAS, FEEDBACK 😭

this document, and the package it describes, will undoubtedly contain bugs and other problems. please report such in the category yaml of the Tcllib Trackers [http://core.tcl.tk/tcllib/reportlist]. please also report any ideas for enhancements you may have for either package and/or documentation. 🫢

when proposing code changes, please provide unified diffs, i.e. the output of diff -u.

note further that attachments are strongly preferred over inlined patches. attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar. πŸ’…


🧚 SEE ALSO 🧚

base64, huddle, json


⭐ KEYWORDS ⭐

data exchange, huddle, parsing, text processing, yaml


Copyright (c) 2008 KATO Kanryu <kanryu6@users.sourceforge.net>


okay that's the whole page bestie, you ate it πŸ’– this one shipped with tcllib version 0.4.2 and it's dated yaml(n) β€” go forth and parse, you main character πŸŽ€βœ¨

πŸ“¦ where this page comes from