deno.com

Parsing and serializing YAML

在 Github 上编辑

YAML is a widely used data serialization language designed to be easily human readable and writeable.

import { parse, stringify } from "jsr:@std/yaml";
To parse a YAML string, you can use the the standard library's YAML parse function. The value is returned as a JavaScript object.
const text = `
foo: bar
baz:
  - qux
  - quux
`;
const data = parse(text);
console.log(data.foo);
console.log(data.baz.length);
To turn a JavaScript object into a YAML string, you can use the standard library's YAML stringify function.
const obj = {
  hello: "world",
  numbers: [1, 2, 3],
};
const yaml = stringify(obj);
console.log(yaml);
// hello: word
// numbers:
//   - 1
//   - 2
//   - 3

使用 Deno CLI 在本地运行 此示例

deno run https://docs.denohub.com/examples/scripts/parsing_serializing_yaml.ts

你找到需要的内容了吗?

隐私政策