
Product
Secure Your AI-Generated Code with Socket MCP
Socket MCP brings real-time security checks to AI-generated code, helping developers catch risky dependencies before they enter the codebase.
html-to-json-parser
Advanced tools
This library is capable to convert HTML string/element to JSON/JS Object or JSON to HTML.
From
<div class="container">
<ul>
<li>Hello <strong>World</strong></li>
</ul>
</div>
To
{
"type": "div",
"attributes": {
"class": "container"
},
"content": [
{
"type": "ul",
"content": [
{
"type": "li",
"content": [
"Hello ",
{
"type": "strong",
"content": [
"World"
]
}
]
}
]
}
]
}
Install html-to-json-parser with npm/yarn
npm install html-to-json-parser // npm
yarn add html-to-json-parser // yarn
Convert HTML to JSON or JavaScript Object
// Imports
import { HTMLToJSON } from 'html-to-json-parser'; // ES6
const { HTMLToJSON } = require('html-to-json-parser'); // CommonJS
// Data
const element = '<div><ul><li>Hello <strong>World</strong></li></ul></div>'; // HTML string
const element = document.querySelector('div'); // HTML element
// Conversion
let result = await HTMLToJSON(element, true); // Default: false - true: return JSON, false: return JS Object
Convert JSON to HTML using JavaScript
// Imports
import { JSONToHTML } from 'html-to-json-parser'; // ES6
const { JSONToHTML } = require('html-to-json-parser'); // CommonJS
// Data: JSON or JS Object
const data = {
type: "div",
attributes: {
class: "container"
},
content: [
{
type: "ul",
content: [
{
type: "li",
content: [
"Hello ",
{
type: "strong",
content: [
"World"
]
}
]
}
]
}
]
};
// Conversion
let result = await JSONToHTML(data, false); // Default: true - true: return HTML String, false: return HTML Element
Convert JSON to HTML using TypeScript
// Imports
import { JSONToHTML, JSONType } from 'html-to-json-parser'; // ES6
const { JSONToHTML, JSONType } = require('html-to-json-parser'); // CommonJS
// Data: JSON or JS Object
const data: JSONType = {
type: "div",
attributes: {
class: "container"
},
content: [
{
type: "ul",
content: [
{
type: "li",
content: [
"Hello ",
{
type: "strong",
content: [
"World"
]
}
]
}
]
}
]
};
// Conversion
let result = await JSONToHTML(data, false); // Default: true - true: return HTML String, false: return HTML Element
git checkout -b my-new-feature
git commit -am 'Add some feature'
git push origin my-new-feature
html-to-json-parser © Yousuf
Authored and maintained by Yousuf Kalim.
GitHub @yousufkalim · LinkedIn @yousufkalim
FAQs
This library converts HTML to JSON or JSON to HTML tree
The npm package html-to-json-parser receives a total of 6,326 weekly downloads. As such, html-to-json-parser popularity was classified as popular.
We found that html-to-json-parser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket MCP brings real-time security checks to AI-generated code, helping developers catch risky dependencies before they enter the codebase.
Security News
As vulnerability data bottlenecks grow, the federal government is formally investigating NIST’s handling of the National Vulnerability Database.
Research
Security News
Socket’s Threat Research Team has uncovered 60 npm packages using post-install scripts to silently exfiltrate hostnames, IP addresses, DNS servers, and user directories to a Discord-controlled endpoint.