{"route":"/en-US-v0.13.1/reference/data-loading/yaml/","title":"YAML","description":"Documentation for the `yaml` function.","part":null,"outline":[{"id":"summary","name":"Summary","children":[]},{"id":"example","name":"Example","children":[]},{"id":"parameters","name":"Parameters","children":[{"id":"parameters-source","name":"source","children":[]}]},{"id":"definitions","name":"Definitions","children":[{"id":"definitions-decode","name":"Decode YAML","children":[{"id":"definitions-decode-data","name":"data","children":[]}]},{"id":"definitions-encode","name":"Encode YAML","children":[{"id":"definitions-encode-value","name":"value","children":[]}]}]}],"body":{"kind":"func","content":{"path":[],"name":"yaml","title":"YAML","keywords":[],"oneliner":"Reads structured data from a YAML file.","element":false,"contextual":false,"deprecation":null,"details":"<p>Reads structured data from a YAML file.</p>\n<p>The file must contain a valid YAML object or array. YAML mappings will be\nconverted into Typst dictionaries, and YAML sequences will be converted into\nTypst arrays. Strings and booleans will be converted into the Typst\nequivalents, null-values (<code>null</code>, <code>~</code> or empty ``) will be converted into\n<code><span class=\"typ-key\">none</span></code>, and numbers will be converted to floats or integers depending on\nwhether they are whole numbers. Custom YAML tags are ignored, though the\nloaded value will still be present.</p>\n<p>Be aware that integers larger than 2<sup>63</sup>-1 will be converted to\nfloating point numbers, which may give an approximative value.</p>\n<p>The YAML files in the example contain objects with authors as keys,\neach with a sequence of their own submapping with the keys\n&quot;title&quot; and &quot;published&quot;</p>\n<h2 id=\"example\">Example</h2>\n<div class=\"previewed-code\"><pre><code><span class=\"typ-key\">#</span><span class=\"typ-key\">let</span> <span class=\"typ-func\">bookshelf</span><span class=\"typ-punct\">(</span>contents<span class=\"typ-punct\">)</span> <span class=\"typ-op\">=</span> <span class=\"typ-punct\">{</span>\n  <span class=\"typ-key\">for</span> <span class=\"typ-punct\">(</span>author<span class=\"typ-punct\">,</span> works<span class=\"typ-punct\">)</span> <span class=\"typ-key\">in</span> contents <span class=\"typ-punct\">{</span>\n    author\n    <span class=\"typ-key\">for</span> work <span class=\"typ-key\">in</span> works <span class=\"typ-punct\">[</span>\n      <span class=\"typ-marker\">-</span> <span class=\"typ-pol\">#</span><span class=\"typ-pol\">work</span><span class=\"typ-punct\">.</span><span class=\"typ-pol\">title</span> (<span class=\"typ-pol\">#</span><span class=\"typ-pol\">work</span><span class=\"typ-punct\">.</span><span class=\"typ-pol\">published</span>)\n    <span class=\"typ-punct\">]</span>\n  <span class=\"typ-punct\">}</span>\n<span class=\"typ-punct\">}</span>\n\n<span class=\"typ-func\">#</span><span class=\"typ-func\">bookshelf</span><span class=\"typ-punct\">(</span>\n  <span class=\"typ-func\">yaml</span><span class=\"typ-punct\">(</span><span class=\"typ-str\">&quot;scifi-authors.yaml&quot;</span><span class=\"typ-punct\">)</span>\n<span class=\"typ-punct\">)</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.13.1/assets/ce1cef3a36cd7879dbe19609834df61b.png\" alt=\"Preview\"></div></div>","example":null,"self":false,"params":[{"name":"source","details":"<p>A <a href=\"/en-US-v0.13.1/reference/syntax/#paths\">path</a> to a YAML file or raw YAML bytes.</p>","example":null,"types":["str","bytes"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false}],"returns":["any"],"scope":[{"path":["yaml"],"name":"decode","title":"Decode YAML","keywords":[],"oneliner":"Reads structured data from a YAML string/bytes.","element":false,"contextual":false,"deprecation":"`yaml.decode` is deprecated, directly pass bytes to `yaml` instead","details":"<p>Reads structured data from a YAML string/bytes.</p>","example":null,"self":false,"params":[{"name":"data","details":"<p>YAML data.</p>","example":null,"types":["str","bytes"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false}],"returns":["any"],"scope":[]},{"path":["yaml"],"name":"encode","title":"Encode YAML","keywords":[],"oneliner":"Encode structured data into a YAML string.","element":false,"contextual":false,"deprecation":null,"details":"<p>Encode structured data into a YAML string.</p>","example":null,"self":false,"params":[{"name":"value","details":"<p>Value to be encoded.</p>","example":null,"types":["any"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false}],"returns":["str"],"scope":[]}]}}}