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
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 markup2jsonYarn
yarn add markup2jsonpnpm
pnpm add markup2jsonUsage
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!"
}
]
}
]
}