Skip to main content

json2htmls is a package that converts any json to html tables.

Project description

json2htmls

json2htmls is a package that converts json (dict) to html tables.

Installation

Use the package manager pip to install json2htmls.

pip install json2htmls

Available methods

json_to_html - converts json (dict) to html
normalize - normalizes json (dict) , converts values to strings
builder - main method that generates tables
json_arrays_to_dictionary - converts array of objects to objects , with suffixes
json_arrays_destroy - removes arrays from source

Usage

Example

from json2htmls import json_to_html
import json
with open('tests/sample.json') as json_file: # warning currently keys with values are not supported , e.g. "key": ["1", "2"]
    data = json.load(json_file)
source , html = json_to_html(data) # source is the dictionary , html is the html itself

Result , use htmlviewer to see the result

<!DOCTYPE html>
<html>
  <head>
    <title>Report</title>
    <style>table { page-break-inside:auto } tr { page-break-inside:avoid; page-break-after:auto } thead { display:table-header-group } tfoot { display:table-footer-group } .pointer { display: block; clear: both; page-break-after: always; } .clearfix { overflow: auto; clear: both } .clearfix::after { content: &quot;&quot;; clear: both; display: table; } body { margin: 0 7rem; } table { width: 100%; font-size: 0.8rem; } th,td { border: 0.11rem solid black; } table, th,td { border-collapse: collapse; padding: 0.25rem 1rem; text-align: left; margin: 0; } tr:nth-child(even) { background-color: #cccccc61; } </style>
  </head>
  <body>
    <table class="clearfix" id="table_id">
      <tbody>
        <div class="pointer"></div>
        <h3>General</h3>
        <tr>
          <th>Id</th>
          <td>0001</td>
        </tr>
        <tr>
          <th>Type</th>
          <td>donut</td>
        </tr>
        <tr>
          <th>Name</th>
          <td>Cake</td>
        </tr>
        <tr>
          <th>Ppu</th>
          <td>0.55</td>
        </tr>
        <tr></tr>
      </tbody>
    </table>
    <table class="clearfix" id="table_batter" style="page-break-inside: avoid; margin-top: 2rem;">
      <tbody>
        <tr id="row_heading_batter_heading">
          <td colspan="2">
            <h3 class="clearfix">Batter - 4</h3>
          </td>
        </tr>
        <tr id="row_heading_batter_0">
          <th>Id</th>
          <th>Type</th>
        </tr>
        <tr id="row_batter_0">
          <td>1001</td>
          <td>Regular</td>
        </tr>
        <tr id="row_batter_1">
          <td>1002</td>
          <td>Chocolate</td>
        </tr>
        <tr id="row_batter_2">
          <td>1003</td>
          <td>Blueberry</td>
        </tr>
        <tr id="row_batter_3">
          <td>1004</td>
          <td>Devil's Food</td>
        </tr>
      </tbody>
    </table>
    <h3>Batters</h3>
    <table class="clearfix" id="table_batters">
      <tbody></tbody>
    </table>
    <table class="clearfix" id="table_topping" style="page-break-inside: avoid; margin-top: 2rem;">
      <tbody>
        <tr id="row_heading_topping_heading">
          <td colspan="2">
            <h3 class="clearfix">Topping - 7</h3>
          </td>
        </tr>
        <tr id="row_heading_topping_0">
          <th>Id</th>
          <th>Type</th>
        </tr>
        <tr id="row_topping_0">
          <td>5001</td>
          <td>None</td>
        </tr>
        <tr id="row_topping_1">
          <td>5002</td>
          <td>Glazed</td>
        </tr>
        <tr id="row_topping_2">
          <td>5005</td>
          <td>Sugar</td>
        </tr>
        <tr id="row_topping_3">
          <td>5007</td>
          <td>Powdered Sugar</td>
        </tr>
        <tr id="row_topping_4">
          <td>5006</td>
          <td>Chocolate with Sprinkles</td>
        </tr>
        <tr id="row_topping_5">
          <td>5003</td>
          <td>Chocolate</td>
        </tr>
        <tr id="row_topping_6">
          <td>5004</td>
          <td>Maple</td>
        </tr>
      </tbody>
    </table>
  </body>
</html>

Contributing

Pull requests are welcome. Open issues addressing pull requests.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

json2htmls-0.0.21.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

json2htmls-0.0.21-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

Details for the file json2htmls-0.0.21.tar.gz.

File metadata

  • Download URL: json2htmls-0.0.21.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5

File hashes

Hashes for json2htmls-0.0.21.tar.gz
Algorithm Hash digest
SHA256 9929ac24e0ab7d6cb97b15325996f0c38438d99f7718148600e03e0532fe0d11
MD5 ab56bef46c37002493598cc9aef7265a
BLAKE2b-256 f01bc602118df8b37e382b253f9f12c5e55c3b6bbc3696894d585623df60136c

See more details on using hashes here.

File details

Details for the file json2htmls-0.0.21-py3-none-any.whl.

File metadata

  • Download URL: json2htmls-0.0.21-py3-none-any.whl
  • Upload date:
  • Size: 3.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5

File hashes

Hashes for json2htmls-0.0.21-py3-none-any.whl
Algorithm Hash digest
SHA256 bf0fc735617227865a836694f0b2a465d104b22849329a5a78ef7d63ffbf9695
MD5 9500c9afa9762b72a3d64b22a05b4ff5
BLAKE2b-256 622ebfd780aee7011d298286212c36e192c91b7e1f8d728f27e8a86a006ee877

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page