https://github.com/kevinhermawan/markup2json
A library for converting HTML and XML into JSON
https://github.com/kevinhermawan/markup2json
html-parser html-to-json html2json javascript typescript xml-parser xml-to-json xml2json
Last synced: about 1 month ago
JSON representation
A library for converting HTML and XML into JSON
- Host: GitHub
- URL: https://github.com/kevinhermawan/markup2json
- Owner: kevinhermawan
- License: mit
- Created: 2023-01-21T18:51:07.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-03T14:57:36.000Z (about 2 years ago)
- Last Synced: 2025-09-09T00:37:17.019Z (about 1 month ago)
- Topics: html-parser, html-to-json, html2json, javascript, typescript, xml-parser, xml-to-json, xml2json
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/markup2json
- Size: 384 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
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](https://github.com/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
```ts
import markup2json from "markup2json";
// import markup2json from "npm:markup2json"; // (for Deno)const html = "
";Hello, World!
const json = markup2json(html);console.log(json);
```**Output**
```json
{
"tag": "div",
"attributes": {
"class": "container"
},
"children": [
{
"tag": "p",
"children": [
{
"tag": "#text",
"text": "Hello, World!"
}
]
}
]
}
```## License
[MIT License](/LICENSE)