markup2json
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

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

Package Sidebar

Install

npm i markup2json

Weekly Downloads

11

Version

1.0.5

License

MIT

Unpacked Size

5.54 kB

Total Files

5

Last publish

Collaborators

  • khermawan