1.0.0 • Published 8 years ago

@arch-mage/json-html v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
8 years ago

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:

  1. tag <String>: html tag name.
  2. attrs <Object>: tag attributes.
  3. closed <Boolean>: to determine wether the tag is closed (<tag/>) or not (<tag></tag>).
  4. 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