node package manager


An HTML formatter for JSON data

json2html simply takes a json structure as an input and returns an html string. It can be nice for exploring your data - but don't expect too much of it.

npm install json2html
var http = require('http'); var json2html = require('json2html')
http.createServer(function (req, res) {
var myJson = {
a_table: [
{name: 'hugo', tel: '1234561234', email: ''},
{name: 'joe', tel: '1234569999', email: ''}
straigh_array: ['a','b','c'],
an_object: {
myAttribute: {a:1, b:2},
anotherAttribute: {r:1, d:2}
  res.writeHead(200, {'Content-Type': 'text/html'});
}).listen(1337, '');

This will produce a page with this html (plus some minimalistic css formatting / javascript to exand or collapse content)

require('json2html').render(json, options)

json is the json object you want to convert into HTML options is a json object, the only option available so far is plainHtml (use {plainHtml: true}) if you want to instrument the page with your own event and disable the admittedly basic onclick events embedded in the HTML (for expanding / collapsing)