html2json -- Convert Html to Json
Convert HTML to JSON library.
Simple to use
let toJson = ; //return a json object;
html2json is designed to convert html to json object, JQuery like.
let mapping = title: "head>title"; //json = {"title": "THE html title"}let json = ;
Attribute
get title element text by default.
title: "head>title";
to get attribute 'href'.
title: selector: "some <a> Tag" attr: "href"
Foreach
use foreach like this.
const mapping = results: selector: ".result" foreach: title: ".c-title>a" url: selector: ".c-title>a" attr: "href" ;
Function
object value could be a function with an parameter "element", which is an cheerio object.
const mapping = { let text = element text ; return text0; };
Current Element
use "." to represent the current element.
const mapping = results: selector: ".result" foreach: title: ".c-title>a" id: selector: "." attr: "id" ;
Test Useage
yarn test