Skip to content

ParseYML

YAML configs without the "why won't this indent" headache.

What is it?

ParseYML parses YAML strings into JavaScript objects (and stringifies objects back to YAML). Handy for config files, structured settings, or any time someone hands you YAML and expects you to make sense of it.

Access it as modules.ParseYML.


How to use

Parse a YAML string — sync, no await:

let result = modules.ParseYML.parse("name: Alice\nage: 25")
// { name: "Alice", age: "25" }

Stringify an object back to YAML:

let yaml = modules.ParseYML.stringify({ name: "Alice", age: 25 })
// "name: Alice\nage: 25\n"

Methods

Method Returns Description
parse(yamlString, options?) object Parse YAML into a JavaScript object
stringify(object, options?) string Convert an object to YAML text

Try it

Load bot config from YAML

Bot sends to chat. Store config in db as a YAML string, parse on read:

let raw = db.bot.get("config_yaml") || "theme: dark\nlang: en"
let config = modules.ParseYML.parse(raw)

Bot.sendMessage("Theme: " + config.theme + ", Language: " + config.lang)

Parse user-submitted YAML

params might contain YAML the user pasted:

try {
  let data = modules.ParseYML.parse(params)
  Bot.sendMessage("Parsed " + Object.keys(data).length + " top-level keys.")
} catch (err) {
  Bot.sendMessage("Invalid YAML: " + err.message)
}

Save settings as YAML

let settings = { notifications: true, theme: "dark", lang: "en" }
let yaml = modules.ParseYML.stringify(settings)
db.user.set("settings_yaml", yaml)
Bot.sendMessage("Settings saved.")

Limits

Limit Value
Input size Plan buffer size (512 KB – 10 MB)
Schema FAILSAFE_SCHEMAall values are strings
Method Sync

parse() uses FAILSAFE_SCHEMA for safety — numbers and booleans in YAML become strings ("25", not 25). Convert types yourself after parsing.

Exceeding input size throws: Input exceeds plan limit (N bytes).


Notes

  • Sync — no await needed
  • YAML indentation matters — spaces, not tabs (YAML's eternal rule)
  • All parsed values are strings under FAILSAFE_SCHEMA
  • For tabular data, use ParseCSV
  • Official package: js-yaml on npm