Giter VIP home page Giter VIP logo

json2html's Introduction

JSON2HTML

project to generate html from json. By default, the script searches for the source file in its source.json and sends data from it to the converter. The result is a file index.htm. Tags for html are specified as keys in json. If the json contains a list , the entire html is wrapped in <ul> and each element is wrapped in a li. if an element contains a list too, then the entire element is wrapped in <ul> and each sub-element in the list is wrapped in <li>.

Tag name can include classes and ID. To specify a class, write it through a dot; to specify an id, write it through a grid. Like in emmet. example: a.active.visible#main-page -> <a class="active visible" id="main-page">

REQUIREMENT

  • python3
  • pytest (for testing)

HOW TO RUN

  • write sourece json to file source.json
  • run script converter.py
    python3 converter.py
    

AGRGUMENTS

name default description
-s,--source-file source file format json source.json
-o,--output-file output file format html index.html

TEST

run pytest

pytest

EXAMPLE

Run script with source file my_json.json and output file result.html

Example json:

[
    {
        "h1": "Title #1",
        "content": [
            {
                "h4.active#content-1": "sub-conten"
            },
            {
                "span.escape#span": "script escape content: <script>alert()</script>"
            }
        ]
    },
    {
        "h2": "Title #2",
        "span": "Hello, World 2!"
    }
]
python3 -s my_json.json -o result.html

result.html

<ul><li><h1>Title #1</h1><content><ul><li><h4 class="active" id="content-1">sub-conten</h4></li><li><span class="escape" id="span">script escape content: &lt;script&gt;alert()&lt;/script&gt;</span></li></ul></content></li><li><h2>Title #2</h2><span>Hello, World 2!</span></li></ul>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.