Turn HTML DOM to JSON-able structure
👌 Zero dependencies ⚡️ Ultra lightweight
npm i -S jsonfromhtml
const jsonFromHTML = const body = // returns objectconst json = JSON
Usage
const element =
Parameter:
domElement
: Expects a DOM element. Use a package like cheerio to use it in node envoirnment.
Returns:
- An
Object
.
Object
Example
Returned Input:
Here is my Github if you wanna have a looksy.
Output:
"nodeName": "P" // tag name "nodeType": "element" // either 'element' or 'text' "attrs": {} // only for nodeType == 'element' "children": "content": "\nHere is my " "nodeType": "text" "nodeName": "A" "nodeType": "element" "attrs": // key-value pairs of all the attributes on the element. "href": "https://github.com/moinism" "target": "_blank" "children": "content": "Github" "nodeType": "text" "content": " if you wanna have a looksy.\n" "nodeType": "text"
LICENSE
MIT