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

yaml-to-json-core

v0.1.0

Published

YAML ⇄ JSON conversion with human-readable errors and YAML 1.1 vs 1.2 (Norway problem) warnings — the engine behind yamltojsonfree.com

Readme

yaml-to-json-core

YAML ⇄ JSON conversion with error messages a human can act on, and warnings for every value whose meaning changes between YAML 1.1 and YAML 1.2.

This is the engine behind yamltojsonfree.com — a free, browser-only YAML to JSON converter, JSON to YAML converter, YAML validator and comment-preserving YAML formatter. Pure TypeScript, no DOM, ~30 kB minified, runs in Node and the browser.

import { yamlToJson } from 'yaml-to-json-core';

const result = yamlToJson('name: app\nports: [80, 443\n');

if (!result.ok) {
  console.log(result.error.message); // A flow sequence opened with “[” is never closed.
  console.log(result.error.hint);    // Add the matching “]”, or rewrite the list in block style…
  console.log(result.error.line);    // 2   ← the line where “[” was opened, not where js-yaml gave up
}

Why another YAML library?

It isn’t one — parsing is done by js-yaml (conversion) and yaml (formatting). What this package adds is everything a converter needs around a parser:

| | What you get | |---|---| | Real error messages | js-yaml reports an unclosed bracket, brace or quote as “deficient indentation” at an unrelated line. describeError() recovers the actual delimiter and where it opened, and translates the dozen most common parser messages into a sentence plus a fix. Both parsers’ wording is covered, so the same mistake reads the same way whichever engine raised it. | | YAML 1.1 vs 1.2 warnings | country: NO is the string "NO" in YAML 1.2 and the boolean false in YAML 1.1 — the Norway problem. findGotchas() walks the parser’s event stream and reports every plain scalar that changes meaning between versions (booleans, leading-zero octals, 12:30 sexagesimals, bare exponents), with exact offsets and what each version produces. Quoted values are never flagged. | | Multi-document streams | ----separated input becomes a JSON array or JSON Lines (one object per line, what kubectl expects), with the document count reported. | | Merge keys under YAML 1.2 | js-yaml’s Core schema drops <<, which silently breaks Docker Compose and GitLab CI files. Merge keys are resolved by default and can be switched off. | | Alias-bomb protection | A “billion laughs” document is rejected by node budget before anything walks the structure — js-yaml’s maxAliases counts alias tokens, not the nodes they expand to. | | Safe JSON → YAML | Output uses a schema that quotes anything either YAML version would read as a non-string, so it round-trips through PyYAML, Go and JavaScript parsers alike. | | Comment-preserving formatting | formatYaml() reflows indentation and quoting while keeping every comment attached to its line, using the yaml package’s concrete syntax tree. |

Install

npm install yaml-to-json-core

Requires Node 20+ or any modern browser. ESM only.

API

yamlToJson(input, options?)Result

import { yamlToJson, DEFAULTS } from 'yaml-to-json-core';

const r = yamlToJson(src, { ...DEFAULTS, indent: '4', sortKeys: true, multiDoc: 'ndjson' });
if (r.ok) {
  r.output;    // string — the JSON
  r.docCount;  // number of YAML documents found
  r.notes;     // e.g. "3 comments dropped — JSON has no syntax for comments."
  r.gotchas;   // values that differ between YAML 1.1 and 1.2 (see below)
} else {
  r.error;     // ParseError — message, hint, line, column, position, raw
  r.gotchas;
}

jsonToYaml(input, options?)Result

JSON in, YAML out. Ambiguous strings ("no", "yes", "on", "off", "022", "12:30") come out quoted so a YAML 1.1 consumer reads them back as strings.

formatYaml(input, options?)Result

Comment-preserving reformat. The yaml package is loaded lazily; call await loadYamlModule() once before the first formatYaml().

convert(input, direction, options?)Result

Dispatches to one of the three by direction: 'yaml-to-json' | 'json-to-yaml' | 'yaml-format'.

findGotchas(src)Gotcha[]

Standalone Norway-problem detector. Each hit carries line, column, position, end, the literal text, as11, as12, a message and a hint.

findGotchas('country: NO\nmode: 0644\n');
// [
//   { text: 'NO',   as11: 'false', as12: '"NO"', line: 1, … },
//   { text: '0644', as11: '420',   as12: '644',  line: 2, … },
// ]

describeError(err, src)ParseError

Turn a thrown js-yaml or yaml error into { message, hint?, line?, column?, position?, raw }. Useful if you run the parser yourself and only want the translations.

Options

| Option | Values | Default | Notes | |---|---|---|---| | version | '1.2' | '1.1' | '1.2' | Which YAML schema to parse with. Gotchas are only reported under 1.2. | | mergeKeys | boolean | true | Resolve <<: merge keys. Off makes << a literal key. | | indent | '2' | '4' | 'tab' | 'minified' | '2' | JSON indentation. YAML output falls back to 2 for tab/minified. | | sortKeys | boolean | false | Sort object keys recursively. | | multiDoc | 'array' | 'ndjson' | 'array' | How --- streams are combined. | | maxAliases | number | 10000 | Passed to js-yaml; the node-budget guard applies regardless. |

Background reading

The behaviour above is documented at length on the site:

Development

npm install
npm run build   # tsc → dist/
npm test        # 90 fixture checks, no test framework

src/convert.ts, src/errors.ts and src/gotchas.ts are the same files the site ships (only the .js import extensions differ); behaviour changes land here first and are then mirrored there.

License

MIT © yamltojsonfree