js-yaml: A YAML 1.2 Parser and Dumper for JavaScript That Passes the Full Test Suite
JavaScript YAML parser and dumper. Very fast. Supports both the 1.2 and 1.1 specs, and passes the entire YAML Test Suite.
At a glance
- What is it?
- js-yaml is a JavaScript library that parses and serializes YAML, supporting both 1.2 and 1.1 specs. It is the only library that passes the entire YAML Test Suite, making it a reliable choice for strict YAML compliance.
- Who is it for?
- Adopt js-yaml if you need a YAML parser that strictly adheres to the 1.2 spec and can handle the full YAML Test Suite, especially in Node.js or browser environments. Avoid it if you need a parser with active recent development or if your use case requires a parser that is not tied to the nodeca ecosystem.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 3 days ago.
- What is it written in?
- Mainly TypeScript, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on September 14, 2026, and from our analysis. They are not legal advice.
DEEP OPEN-SOURCE ANALYSIS
The Problem: YAML Parsing in JavaScript Is Often Spec-Loose
YAML is a common configuration format, but JavaScript parsers have historically varied in spec compliance. Many libraries support only a subset of YAML 1.1 or have quirks with anchors, tags, or multi-document streams. For engineers who need deterministic behavior, a parser that passes the official YAML Test Suite is a practical requirement. js-yaml addresses this directly: the README states it supports both YAML 1.2 and 1.1 and passes the entire YAML Test Suite. That suite is a set of over 200 test cases covering edge cases like explicit tags, merge keys, and flow collections. If your project depends on YAML behavior that matches the spec, js-yaml gives you a baseline that other libraries may not offer.
How It Works: Two Specs, One Codebase
js-yaml provides two core functions: load and dump. The load function takes a YAML string and returns a JavaScript object, while dump takes a JavaScript object and returns a YAML string. The library is implemented in TypeScript, as indicated by the repository's primary language, but it is distributed as a JavaScript module for npm. The dual spec support is not just a flag; it means the parser can handle both the 1.2 and 1.1 syntax, which differ in subtle ways like how booleans are represented (yes/no vs. true/false). The README's example shows a simple load call wrapped in a try-catch, which is a reminder that YAML errors, such as malformed syntax or duplicate keys, are thrown as exceptions. The dump function serializes JavaScript objects, but it does not preserve the original YAML formatting or comments, which is a common limitation across serializers.
Getting It Running: Install and First Commands
Installation is straightforward via npm: run npm install js-yaml in your project directory. The README shows two usage patterns. For parsing, import { load } from 'js-yaml' and call load('greeting: hello'), which returns an object with a greeting property. For dumping, import { dump } and call dump({ greeting: 'hello' }) to get a YAML string. The library supports both CommonJS and ES modules, as the import syntax suggests. There is also an online demo hosted at nodeca.github.io/js-yaml, which lets you try the parser without installing anything. The documentation is linked from the README at nodeca.github.io/js-yaml/doc, and more usage examples are in docs/usage.md in the repository. No configuration files or build steps are required for basic use.
A Genuine Limitation: The Dumper Is Not a Formatter
A real limitation is that dump is not a YAML formatter. If you load a YAML file, modify a value, and dump it back, the output will not preserve the original indentation, key order, or comments. The library does not claim to do this, but it is a common expectation. For example, a YAML file with comments explaining configuration options will lose those comments after a dump. This makes js-yaml unsuitable for round-tripping YAML files that humans maintain, such as Ansible playbooks or Kubernetes manifests. For those cases, you need a serializer that preserves comments, which js-yaml does not. Also, the library supports both specs, but the README does not specify how to select between 1.1 and 1.2; the documentation likely has options, but the material given does not show them, so you must check the docs for that.
Alternative: yaml Package and Its Different Approach
The main alternative is the yaml package (also on npm). While js-yaml focuses on passing the YAML Test Suite, the yaml package takes a different approach: it aims for a more feature-rich API, including support for custom tags, a CST (concrete syntax tree) for comment preservation, and the ability to parse and stringify documents with comments. That means yaml is better for round-tripping, but its compliance with the YAML Test Suite is not as prominently advertised. In contrast, js-yaml's strength is its strict spec adherence, which is a trade-off: you get compliance but lose comment preservation. If your application only needs to read YAML and convert it to JSON or JavaScript objects, js-yaml is sufficient. If you need to edit YAML files programmatically without destroying comments, yaml is the better choice.
Maintenance and License: What You Should Know
The repository is not archived, but there are no recent releases listed and the last push date is unknown. This could be a sign of a stable project or a slowing one. The license is MIT, which means you can use it in commercial projects with minimal restrictions, but you should verify the license file for any specific attribution requirements. The library is written in TypeScript, which suggests that type definitions are likely included, but the README does not confirm this. For maintenance cost, the lack of recent releases means you may not get fixes for new security vulnerabilities or YAML spec updates. The YAML Test Suite is a static set, so passing it does not guarantee future spec changes. You should check the repository's issue tracker for any open problems, but the material given does not provide that information.
Who Should Use It: A Concrete Assessment
js-yaml is a good fit for projects that need to parse YAML configuration files with strict spec compliance, such as tools that validate YAML against the 1.2 spec or that must handle edge cases like multi-document streams. It is also suitable for applications that only need to serialize JavaScript objects to YAML for output, as the dump function is straightforward. However, it is the wrong tool for projects that require comment preservation or that need to maintain YAML files as human-readable artifacts. If you are building a CI tool that reads a YAML file and outputs a JSON representation, js-yaml works. If you are building an editor that lets users edit YAML with comments, look elsewhere. Before adopting, verify that the spec support meets your needs: the README says it supports 1.2 and 1.1, but the exact behavior for 1.1 is not detailed in the given material, so consult the documentation for options like schema selection.
Editorial conclusion
Adopt js-yaml if you need a YAML parser that strictly adheres to the 1.2 spec and can handle the full YAML Test Suite, especially in Node.js or browser environments. Avoid it if you need a parser with active recent development or if your use case requires a parser that is not tied to the nodeca ecosystem. Before adopting, verify that the lack of recent releases does not affect your security posture, and check the documentation for any known edge cases in the 1.1 compatibility mode.
Community notes