UNPKG

json2dom

Version:

A utility for generating DOM string from JSON

42 lines (32 loc) 666 B
A very simple utility for generating HTML from a JSON. Useful while working with isomorphic apps where you need to share markup between client and server. ```js var json2dom = require("json2dom"); var json = { tagname:"div", attributes:{ id:"hello", class:"world"}, value:"hello, World", children:[ { tagname:"img", attributes:{ src:"hello.png" } }, { tagname:"p", value:"content of child" } ] }; var html = json2dom(json); ``` would create an HTML string like ```html <div id='hello' class='world'> <img src='hello.png'></img> <p>content of child</p> hello, World </div> ```