Home > OS >  Parse YAML file in Google Apps Script
Parse YAML file in Google Apps Script

Time:03-05

I'm trying to parse a YAML file within Google Apps Script. I would like to use the information from a YAML file in Google Sheets.

From what I understood, the underlying library is available (enter image description here

Then you can convert your yaml string into a json object this way:

// your YAML sting

var string =
`foo: bar
stuff:
  foo: bar
  bar: foo
arr:
  - aaa
  - bbb
  - ccc
`

// JSON object

var obj = YAML.eval(string);

console.log(JSON.stringify(obj))

Output:

{
  "foo": "bar",
  "stuff": {
    "foo": "bar",
    "bar": "foo"
  },
  "arr": ["aaa", "bbb", "ccc"]
}
  • Related