JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 8
  • Score
    100M100P100Q21879F
  • License MIT

A library for converting HTML and XML into JSON

Package Exports

  • markup2json
  • markup2json/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (markup2json) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

markup2json

Minified size Test coverage Monthly download

markup2json is a JavaScript library that provides an easy way to convert HTML and XML into JSON format. It uses the @xmldom/xmldom package to parse the input HTML/XML string and convert it into a JSON object. The library is designed to be lightweight, easy to use and compatible with both Node.js and web browsers.

Features

  • Malformed input validation
  • Supports HTML and XML
  • Supports Deno via NPM

Installation

To install markup2json, run the following command:

NPM

npm install markup2json

Yarn

yarn add markup2json

pnpm

pnpm add markup2json

Usage

import markup2json from "markup2json";
// import markup2json from "npm:markup2json"; // (for Deno)

const html = "<div class='container'><p>Hello, World!</p></div>";
const json = markup2json(html);

console.log(json);

Output

{
  "tag": "div",
  "attributes": {
    "class": "container"
  },
  "children": [
    {
      "tag": "p",
      "children": [
        {
          "tag": "#text",
          "text": "Hello, World!"
        }
      ]
    }
  ]
}

License

MIT License