json-html
A simple JSON to HTML converter
INSTALLATION
npm install @arch-mage/json-html
USAGE
Can be used with command line
or js API
JSON structure should be something like this:
{
"tag": "html",
"attrs": {
"lang": "en"
},
"children": [
{
"tag": "head",
"children": [
{
"tag": "meta",
"attrs": {
"charset": "utf-8"
},
"closed": true
},
{
"tag": "title",
"children": "json-html"
}
]
},
{
"tag": "body",
"children": {
"tag": "h1",
"children": "json-html"
}
}
]
}
Then, the output will be like this:
<html lang="en"><head><meta charset="utf-8"/><title>json-html</title></head><body><h1>json-html</h1></body></html>
Known fields are:
-
tag <String>
: html tag name. -
attrs <Object>
: tag attributes. -
closed <Boolean>
: to determine wether the tag is closed (<tag/>
) or not (<tag></tag>
). -
children <String|Object|Array>
: children element.
COMMAND LINE
json-html json.file
json-html < json.file
cat json.file > json-html
JAVASCRIPT API
'use strict';
const jsonHtml = require('json-html');
const json = { tag: 'div' };
const html = jsonHtml(json);
console.log(html); // <div></div>
LICENSE
MIT