@codejockie/json-html
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

json-html

Build Status codecov npm npm bundle size

A simple JSON to HTML parser

API

jsonToHtml - function that converts a JSON data to HTML

Example

Given the following JSON file structure

{
  "_type": "Element",
  "name": "div",
  "children": [
    {
      "_type": "Element",
      "name": "img",
      "attributes": [
        {
          "name": "alt",
          "value": "thumbnail"
        },
        {
          "name": "src",
          "value": "https://via.placeholder.com/150/92c952"
        }
      ]
    },
    {
      "_type": "Element",
      "name": "input",
      "attributes": [
        {
          "name": "type",
          "value": "email"
        },
        {
          "name": "placeholder",
          "value": "Enter email"
        }
      ]
    },
    {
      "_type": "Element",
      "name": "a",
      "attributes": [
        {
          "name": "href",
          "value": "http://example.com"
        }
      ],
      "children": [
        {
          "_type": "Characters",
          "data": "Click here"
        }
      ]
    }
  ]
}
import jsonToHtml from "@codejockie/json-html"

jsonToHtml(jsonData)

// Output
/*
<div>
  <img alt="thumbnail" src="https://via.placeholder.com/150/92c952" />
  <input type="email" placeholder="Enter email" />
  <a href="http://example.com">Click here</a>
</div>
*/

JSON data must be in the format given above with one root element

If you are using ES5, the import statement is: const jsonToHtml = require("@codejockie/json-html").default

Package Sidebar

Install

npm i @codejockie/json-html

Weekly Downloads

2

Version

0.1.0

License

MIT

Unpacked Size

10.3 kB

Total Files

7

Last publish

Collaborators

  • codejockie