to convert html string to json file , and also get data through tag name ,tag id and attribute value.
npm install htm-to-jsonhtml-to-json
=========
A small library providing utility methods for html string.
console
npm install htm-to-json --save
`
Usage
`js
var hObj = require('html-to-json');
var str = "html-to-json praveen";
hObj.convert_html_to_json(str,function(err,data){
if(err) throw err;
console.log(data);
});
`
output:-
`console
{ html: [ { lang: 'en' } ],
head: [],
title: [ { innerHTML: 'html-to-json' } ],
meta:
[ { charset: 'UTF-8' },
div: [ { id: 'username', innerHTML: 'praveen' } ] }
`
Functions
* convert_html_to_json
* get_data_by_id
* get_data_by_tag
* get_data_by_attr_val`js
hObj.convert_html_to_json(str,function(err,jdata){
if(err) throw err;
console.log(jdata);
//get data by tag Id
hObj.get_data_by_id(jdata,'username',function(err,data){
console.log(data);
});
//get data by tag name eg:div
hObj.get_data_by_tag(jdata,'div',function(err,data){
console.log(data);
});
//get data by tag attribute value eg: first_name
hObj.get_data_by_attr_val(jdata,'username',function(err,data){
console.log(data);
});
});
`Tests
`console
npm test.js
``* 0.1.1 Initial release