YAML to JavaScript
Generate JavaScript classes or JSDoc typedefs from a YAML sample.
YAML to JavaScript – Models for plain JS projects
The YAML to JavaScript generator creates code from a YAML sample for projects that do not use TypeScript. Choose ES classes when you want real objects with constructors, or JSDoc @typedef comments when you only want editor autocompletion and type checking without extra runtime code.
How YAML maps to JavaScript
The YAML is parsed with the YAML 1.2 core schema; anchors and aliases are resolved and comments are dropped. Every mapping becomes a class or typedef, nested mappings become their own named models, and sequences of mappings are merged so that one model fits every item. In JSDoc output, keys that are not present in every item are written as optional properties such as [giftWrap].
Output styles
ES classes contain a constructor with one parameter per key, a static fromJSON() factory that builds nested model instances, and a toJSON() method, so Order.fromJSON(parse(text)) gives you a full object tree. JSDoc @typedef output contains only comments – combine it with // @ts-check at the top of a file and /** @type {Order} */ annotations to get type errors in VS Code.
Module formats
Pick ES module for export class declarations, CommonJS for a module.exports block, or Script for plain global classes you can drop into a script tag or a browser console.
Typical uses
Reading configuration in Node.js CLIs, wrapping data from Markdown front matter in Eleventy or Astro, writing scripts around CI or Docker Compose files, and documenting data shapes in a codebase that has not adopted TypeScript.
Tips
Provide a realistic sample with all optional keys present in at least one list item. Timestamps stay strings; convert them with new Date(value) where you need dates.
Related tools
Validate your input with the YAML Validator, convert it with YAML to JSON, or generate typed code with YAML to TypeScript.
Frequently Asked Questions
Why would I generate JSDoc instead of classes?
JSDoc typedefs add no runtime code. With // @ts-check or checkJs enabled, VS Code and tsc use them to autocomplete and type-check plain JavaScript that reads a YAML file.
Which module format should I choose?
Use ES module for modern Node.js and bundlers, CommonJS for require()-based projects, and Script when you paste the classes into a page without a build step.
Does the tool parse YAML at runtime for me?
No. It generates the model code. Parse the file with a library such as yaml or js-yaml and pass the resulting object to the generated static fromJSON() factory.
Is my YAML uploaded?
No. Everything runs locally in your browser.