json2html - Pure Javascript HTML Templating
Last updated 4 months ago by moappi .
Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install node-json2html 
SYNC missed versions from official npm registry.

What is json2html?

json2html is a simple but powerful javascript HTML templating library used to transform JSON objects into HTML.

Check out our website for more information including detailed usage notes, interactive examples and more!

Why json2html?

Instead of writing HTML templates json2html relies on JSON transforms to convert a source JSON objects to html. The benefit of using a JSON transform is that they are already readable by the browser/server and DO NOT require any compilation before use. In addition, json2html allows the following:

  • One template (we call transform) that can be used on either a client OR server
  • Short hand notation for mapping data objects to markup ${name}
  • Event binding to DOM objects (with jquery)
  • Use of inline functions to allow for complex logic during transformation
  • No compilation required


Transform (template)

let transform = 
 {"<>": "li", "id":"${id}", "html":[
	{"<>": "span", "text": "${name} (${year})"}

Plus JSON Data

let data = 
 {"id": 1123, "name": "Jack and Jill", "year":2001};		

Will render the following html

<li id="1123">
	<span>Jack and Jill (2001)</span>

json2html for jQuery

Use seemlessly with jQuery, oh did we also mention that you can embed events in your transforms? Forget attaching your events after you've rendered your templates.

	{"<>":"span","html":"${name} ${year}"}
	alert("You just clicked " +;

Will render into the following html and will alert when clicked :)

<li id=1123>
	<span>Jack and Jill (2001)</span>

json2html for Node.js

Use seemlessly with Node.js


npm install node-json2html


	const json2html = require('node-json2html');
	let html = json2html.transform([{'male':'Bob','female':'Jane'},{'male':'Rick','female':'Ann'}],{"<>":"div","html":"${male} likes ${female}"});

How do I start?

Check out our website for more information including detailed usage notes, downloadable examples and more!

Current Tags

  • 1.4.0                                ...           latest (4 months ago)

6 Versions

  • 1.4.0                                ...           4 months ago
  • 1.3.0                                ...           7 months ago
  • 1.2.0                                ...           2 years ago
  • 1.1.1                                ...           4 years ago
  • 1.0.0                                ...           6 years ago
  • 0.4.1                                ...           7 years ago
Maintainers (1)
Today 0
This Week 4
This Month 3
Last Day 3
Last Week 0
Last Month 7
Dependencies (0)
Dev Dependencies (0)

Copyright 2014 - 2016 © |