npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

yaml2json-api

v1.0.2

Published

A zero-dependency YAML to JSON converter for Node.js

Downloads

364

Readme

yaml2json-api

A zero-dependency YAML to JSON converter for Node.js. Written from scratch — no js-yaml, no yaml, no external libraries. Just 3.9 kB compressed.

npm version


Installation

npm install yaml2json-api

Quick Start

const yaml = require("yaml2json-api");

// Parse a YAML string
const config = yaml.parse(`
server:
  host: localhost
  port: 3000
  debug: true
`);

console.log(config.server.port); // 3000

API Reference

yaml.parse(yamlString)

Parses a YAML string and returns a JavaScript object or array.

Parameters: | Param | Type | Description | |-------|------|-------------| | yamlString | string | YAML content to parse |

Returns: object | array

Example — Object:

const yaml = require("yaml2json-api");

const data = yaml.parse(`
name: John Doe
age: 30
hobbies:
  - reading
  - coding
  - hiking
`);

console.log(data);
// {
//   name: 'John Doe',
//   age: 30,
//   hobbies: ['reading', 'coding', 'hiking']
// }

Example — Array:

const users = yaml.parse(`
- name: Alice
  role: admin
- name: Bob
  role: viewer
`);

console.log(users);
// [
//   { name: 'Alice', role: 'admin' },
//   { name: 'Bob', role: 'viewer' }
// ]

yaml.convertFile(inputPath, outputPath?, indent?)

Converts a .yaml or .yml file to a .json file.

Parameters: | Param | Type | Default | Description | |-------|------|---------|-------------| | inputPath | string | — | Path to the YAML file | | outputPath | string | auto | Output JSON path (defaults to same name with .json) | | indent | number | 2 | JSON indentation spaces |

Returns: { input: string, output: string, data: object }

Example:

const yaml = require("yaml2json-api");

// config.yaml → config.json (auto-named)
const result = yaml.convertFile("./config.yaml");
console.log("Created:", result.output);

// Custom output path
yaml.convertFile("./config.yaml", "./dist/config.json");

// Compact JSON (no indentation)
yaml.convertFile("./config.yaml", "./config.min.json", 0);

yaml.convertDir(dirPath, options?)

Recursively finds all .yaml and .yml files in a directory (including subdirectories) and converts each to a .json file.

Parameters: | Param | Type | Default | Description | |-------|------|---------|-------------| | dirPath | string | — | Directory to search | | options.indent | number | 2 | JSON indentation spaces |

Returns: { converted: string[], failed: { file: string, error: string }[] }

Example:

const yaml = require("yaml2json-api");

const results = yaml.convertDir("./my-project");

console.log(`✓ Converted: ${results.converted.length} files`);
console.log(`✗ Failed: ${results.failed.length} files`);

// List converted files
results.converted.forEach(f => console.log("  →", f));

ES Module Support

Works with both CommonJS and ES Modules:

// CommonJS
const yaml = require("yaml2json-api");

// ES Module (.mjs or "type": "module")
import { parse, convertFile, convertDir } from "yaml2json-api/index.js";

Supported YAML Features

| Feature | Example | Parsed As | |---------|---------|-----------| | Strings | name: hello | "hello" | | Quoted strings | "hello\nworld" | "hello\nworld" | | Single-quoted | 'it''s' | "it's" | | Integers | 42, -17 | 42, -17 | | Hex / Octal | 0xFF, 0o77 | 255, 63 | | Floats | 3.14, 1.5e10 | 3.14, 15000000000 | | Booleans | true, yes, on | true | | Booleans | false, no, off | false | | Null | null, ~, empty | null | | Nested objects | Indentation-based | { a: { b: 1 } } | | Block arrays | - item | ["item"] | | Inline arrays | [1, 2, 3] | [1, 2, 3] | | Inline objects | {a: 1, b: 2} | {a: 1, b: 2} | | Literal blocks | \| | Preserves newlines | | Folded blocks | > | Joins into paragraph | | Block modifiers | \|-, \|+, >-, >+ | Strip/keep trailing newlines | | Comments | # ignored | Stripped | | Inline comments | key: val # note | "val" | | Document markers | ---, ... | Skipped |


Package Info

| | | |-|-| | Size | 3.9 kB compressed, 12 kB unpacked | | Dependencies | Zero | | Node.js | >= 12.0.0 |