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

@qretaio/html2json

v0.5.12

Published

HTML to JSON extractor

Readme

html2json

A Rust port of cheerio-json-mapper.


Overview

  • Input: HTML source + Extractor spec (JSON)
  • Output: JSON matching the structure defined in the spec
  • Available as: Rust crate, CLI tool, and WebAssembly npm package

Installation

npm / WebAssembly

npm install @qretaio/html2json

From crates.io (Rust)

cargo install html2json --features cli

From source

cargo install --path . --features cli
# or from a git repository
cargo install --git https://github.com/qretaio/html2json --features cli

Using just

just install

Usage

JavaScript / TypeScript

import { extract } from "@qretaio/html2json";

const html = `
  <article class="post">
    <h2>My Article</h2>
    <p class="author">John Doe</p>
    <div class="tags">
      <span>rust</span>
      <span>wasm</span>
    </div>
  </article>
`;

const spec = {
  title: "h2",
  author: ".author",
  tags: [
    {
      $: ".tags span",
      name: "$",
    },
  ],
};

const result = await extract(html, spec);
console.log(result);
// {
//   "title": "My Article",
//   "author": "John Doe",
//   "tags": [{"name": "rust"}, {"name": "wasm"}]
// }

CLI

# Extract from file
html2json examples/hn.html --spec examples/hn.json

# Extract from stdin (pipe from curl)
curl -s https://news.ycombinator.com/ | html2json --spec examples/hn.json

# Extract from stdin (pipe from cat)
cat examples/hn.html | html2json --spec examples/hn.json

# Check output matches expected JSON (useful for testing/CI)
html2json examples/hn.html --spec examples/hn.json --check expected.json

CLI Options

  • --spec, -s <FILE> - Path to JSON extractor spec file (required)
  • --check, -c <FILE> - Compare output against expected JSON file. Exits with 0 if match, 1 if differ (with colored diff).

Spec Format

The spec is a JSON object where each key defines an output field and each value defines a CSS selector to extract that field.

Basic Selectors

{
  "title": "h1",
  "description": "p.description"
}

Attributes

{
  "link": "a.main | attr:href",
  "image": "img.hero | attr:src"
}

Pipes (Transformations)

{
  "title": "h1 | trim",
  "slug": "h1 | lower | regex:\\s+-",
  "price": ".price | regex:\\$(\\d+\\.\\d+) | parseAs:int"
}

Available pipes:

  • trim - Trim whitespace
  • lower - Convert to lowercase
  • upper - Convert to uppercase
  • substr:start:end - Extract substring
  • regex:pattern - Regex capture (first group)
  • parseAs:int - Parse as integer
  • parseAs:float - Parse as float
  • attr:name - Get attribute value
  • void - Extract from void elements, useful for extracting xml

Collections (Arrays)

{
  "items": [
    {
      "$": ".item",
      "title": "h2",
      "description": "p"
    }
  ]
}

Scoping ($ selector)

{
  "$": "article",
  "title": "h1",
  "paragraphs": ["p"]
}

Fallback Operators (||)

{
  "title": "h1.main || h1.fallback || h1"
}

Optional Fields (?)

{
  "title": "h1",
  "description?": "p.description"
}

Optional fields that return null are removed from the output.

LICENSE

MIT