{"id":19150234,"url":"https://github.com/softvar/json2html","last_synced_at":"2025-04-08T02:42:27.339Z","repository":{"id":11077905,"uuid":"13423891","full_name":"softvar/json2html","owner":"softvar","description":"🐍 Python module for converting complex JSON to HTML Table representation","archived":false,"fork":false,"pushed_at":"2024-06-27T21:01:56.000Z","size":87,"stargazers_count":277,"open_issues_count":19,"forks_count":86,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-03-31T21:31:40.191Z","etag":null,"topics":["flask-application","html","html-table","json","json2html","python","table"],"latest_commit_sha":null,"homepage":"https://pypi.python.org/pypi/json2html","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/softvar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["softvar"],"patreon":"softvar","open_collective":"softvar","custom":["https://paypal.me/softvar"]}},"created_at":"2013-10-08T19:52:30.000Z","updated_at":"2025-03-13T18:18:26.000Z","dependencies_parsed_at":"2024-01-30T07:03:03.668Z","dependency_job_id":"3b548857-c913-4ddd-8613-8df284284721","html_url":"https://github.com/softvar/json2html","commit_stats":{"total_commits":92,"total_committers":9,"mean_commits":"10.222222222222221","dds":0.5108695652173914,"last_synced_commit":"e1feea273b210d11e4b2e59b9778a0bb4845fbd4"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softvar%2Fjson2html","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softvar%2Fjson2html/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softvar%2Fjson2html/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softvar%2Fjson2html/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/softvar","download_url":"https://codeload.github.com/softvar/json2html/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247607691,"owners_count":20965945,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["flask-application","html","html-table","json","json2html","python","table"],"created_at":"2024-11-09T08:11:11.398Z","updated_at":"2025-04-08T02:42:27.306Z","avatar_url":"https://github.com/softvar.png","language":"Python","readme":"# json2html\n\nPython module to convert `JSON` into a human readable `HTML Table` representation.\n\n![Latest Version](https://img.shields.io/pypi/v/json2html.svg) ![Downloads](https://img.shields.io/pypi/dm/json2html.svg) [![CI](https://github.com/softvar/json2html/workflows/CI/badge.svg?branch=master)](https://github.com/softvar/json2html/actions?query=workflow%3ACI) [![codecov](https://codecov.io/gh/softvar/json2html/branch/master/graph/badge.svg?token=)](https://codecov.io/gh/softvar/json2html)\n\n## Features\n\n- User friendly tabular format, easy to read and share.\n- If the value of the key is an array of objects and all the keys are the same (value of the key is a dict of a list), the module will club by default. E.g.:\n\n    ```bash\n    input = {\n        \"sampleData\": [{\n            \"a\":1, \"b\":2, \"c\":3\n        }, {\n            \"a\":5, \"b\":6, \"c\":7\n        }]\n    }\n    ```\n\n    This will create only one row combining the results. This feature can be turned off by explicitly passing an argument `clubbing = False`.\n\n- The generated table can have some `attributes` explicitly. E.g. giving an `id`, `class`, or any `data-*` attribute.\n- Python 3 compatible.\n\n## Live Demo\n\n[Click here](http://json2html.varunmalhotra.xyz/) for the online demo.\n\n## List of Valid Arguments\n\n`json2html.convert` - The module's `convert` method accepts the following arguments:\n\n| Argument            | Description |\n|---------------------|-------------|\n| `json`              | A valid JSON; This can either be a string in valid JSON format or a Python object that is either dict-like or list-like at the top level. |\n| `table_attributes`  | E.g. pass `id=\"info-table\"` or `class=\"bootstrap-class\"`/`data-*` to apply these attributes to the generated table. |\n| `clubbing`          | Turn on [default]/off clubbing of list with the same keys of a dict / Array of objects with the same key. |\n| `encode`            | Turn on/off [default] encoding of result to escaped HTML, compatible with any browser. |\n| `escape`            | Turn on [default]/off escaping of HTML tags in text nodes (prevents XSS attacks in case you pass untrusted data to json2html). |\n\n## Installation\n\n```bash\npip install json2html\n```\n\nOr, Download [here](https://github.com/softvar/json2html/releases) and run `python setup.py install` after changing directory to `/json2html`\n\n## Example Usage\n\n**Example 1:** Basic usage\n\n```python\nfrom json2html import *\ninput = {\n\t\"name\": \"json2html\",\n\t\"description\": \"Converts JSON to HTML tabular representation\"\n}\njson2html.convert(json = input)\n```\n\nOutput:\n\n```html\n\u003ctable border=\"1\"\u003e\u003ctr\u003e\u003cth\u003ename\u003c/th\u003e\u003ctd\u003ejson2html\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003cth\u003edescription\u003c/th\u003e\u003ctd\u003econverts JSON to HTML tabular representation\u003c/td\u003e\u003c/tr\u003e\u003c/table\u003e\n```\n\n| name        | description                                      |\n|-------------|--------------------------------------------------|\n| json2html   | Converts JSON to HTML tabular representation     |\n\n\n**Example 2:** Setting custom attributes to table\n\n```python\nfrom json2html import *\ninput = {\n\t\"name\": \"json2html\",\n\t\"description\": \"Converts JSON to HTML tabular representation\"\n}\njson2html.convert(json = input, table_attributes=\"id=\\\"info-table\\\" class=\\\"table table-bordered table-hover\\\"\")\n```\n\nOutput:\n\n```html\n\u003ctable id=\"info-table\" class=\"table table-bordered table-hover\"\u003e\u003ctr\u003e\u003cth\u003ename\u003c/th\u003e\u003ctd\u003ejson2html\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003cth\u003edescription\u003c/th\u003e\u003ctd\u003eConverts JSON to HTML tabular representation\u003c/td\u003e\u003c/tr\u003e\u003c/table\u003e\n```\n\n**Example 3:** Clubbing same keys of: Array of Objects\n\n```python\nfrom json2html import *\ninput = {\n\t\"sample\": [{\n\t\t\"a\":1, \"b\":2, \"c\":3\n\t}, {\n\t\t\"a\":5, \"b\":6, \"c\":7\n\t}]\n}\njson2html.convert(json = input)\n```\n\nOutput:\n\n```html\n\u003ctable border=\"1\"\u003e\u003ctr\u003e\u003cth\u003esample\u003c/th\u003e\u003ctd\u003e\u003ctable border=\"1\"\u003e\u003cthead\u003e\u003ctr\u003e\u003cth\u003eb\u003c/th\u003e\u003cth\u003ec\u003c/th\u003e\u003cth\u003ea\u003c/th\u003e\u003c/tr\u003e\u003c/thead\u003e\u003ctbody\u003e\u003ctr\u003e\u003ctd\u003e2\u003c/td\u003e\u003ctd\u003e3\u003c/td\u003e\u003ctd\u003e1\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e6\u003c/td\u003e\u003ctd\u003e7\u003c/td\u003e\u003ctd\u003e5\u003c/td\u003e\u003c/tr\u003e\u003c/tbody\u003e\u003c/table\u003e\u003c/td\u003e\u003c/tr\u003e\u003c/table\u003e\n```\n\n|  a  |  c  |  b  |\n|-----|-----|-----|\n|  1  |  3  |  2  |\n|  5  |  7  |  6  |\n\n\n**Example 4:** Each row for different key(s) of: Array of Objects\n\n```python\nfrom json2html import *\ninput = {\n\t\"sample\": [{\n\t\t\"a\":1, \"b\":2, \"c\":3\n\t}, {\n\t\t\"1a1\":5, \"1b1\":6, \"c\":7\n\t}]\n}\njson2html.convert(json = input)\n```\n\nOutput:\n\n```html\n\u003ctable border=\"1\"\u003e\u003ctr\u003e\u003cth\u003esample\u003c/th\u003e\u003ctd\u003e\u003cul\u003e\u003cli\u003e\u003ctable border=\"1\"\u003e\u003ctr\u003e\u003cth\u003ea\u003c/th\u003e\u003ctd\u003e1\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003cth\u003ec\u003c/th\u003e\u003ctd\u003e3\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003cth\u003eb\u003c/th\u003e\u003ctd\u003e2\u003c/td\u003e\u003c/tr\u003e\u003c/table\u003e\u003c/li\u003e\u003cli\u003e\u003ctable border=\"1\"\u003e\u003ctr\u003e\u003cth\u003e1b1\u003c/th\u003e\u003ctd\u003e6\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003cth\u003ec\u003c/th\u003e\u003ctd\u003e7\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003cth\u003e1a1\u003c/th\u003e\u003ctd\u003e5\u003c/td\u003e\u003c/tr\u003e\u003c/table\u003e\u003c/li\u003e\u003c/ul\u003e\u003c/td\u003e\u003c/tr\u003e\u003c/table\u003e\n```\n\n**Example 5:** [Source: `json.org/example \u003chttp://json.org/example\u003e`_]\n\n```python\nfrom json2html import *\n\ninput = {\n  \"glossary\": {\n\t\t\"title\": \"example glossary\",\n\t\t\"GlossDiv\": {\n\t\t\t\"title\": \"S\",\n\t\t\t\"GlossList\": {\n\t\t\t\t\"GlossEntry\": {\n\t\t\t\t\t\"ID\": \"SGML\",\n\t\t\t\t\t\"SortAs\": \"SGML\",\n\t\t\t\t\t\"GlossTerm\": \"Standard Generalized Markup Language\",\n\t\t\t\t\t\"Acronym\": \"SGML\",\n\t\t\t\t\t\"Abbrev\": \"ISO 8879:1986\",\n\t\t\t\t\t\"GlossDef\": {\n\t\t\t\t\t\t\"para\": \"A meta-markup language, used to create markup languages such as DocBook.\",\n\t\t\t\t\t\t\"GlossSeeAlso\": [\"GML\", \"XML\"]\n\t\t\t\t\t},\n\t\t\t\t\t\"GlossSee\": \"markup\"\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n\njson2html.convert(json = input)\n```\n\nOutput:\n\n```html\n\u003ctable border=\"1\"\u003e\u003ctr\u003e\u003cth\u003eglossary\u003c/th\u003e\u003ctd\u003e\u003ctable border=\"1\"\u003e\u003ctr\u003e\u003cth\u003eGlossDiv\u003c/th\u003e\u003ctd\u003e\u003ctable border=\"1\"\u003e\u003ctr\u003e\u003cth\u003eGlossList\u003c/th\u003e\u003ctd\u003e\u003ctable border=\"1\"\u003e\u003ctr\u003e\u003cth\u003eGlossEntry\u003c/th\u003e\u003ctd\u003e\u003ctable border=\"1\"\u003e\u003ctr\u003e\u003cth\u003eGlossDef\u003c/th\u003e\u003ctd\u003e\u003ctable border=\"1\"\u003e\u003ctr\u003e\u003cth\u003eGlossSeeAlso\u003c/th\u003e\u003ctd\u003e\u003cul\u003e\u003cli\u003eGML\u003c/li\u003e\u003cli\u003eXML\u003c/li\u003e\u003c/ul\u003e\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003cth\u003epara\u003c/th\u003e\u003ctd\u003eA meta-markup language, used to create markup languages such as DocBook.\u003c/td\u003e\u003c/tr\u003e\u003c/table\u003e\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003cth\u003eGlossSee\u003c/th\u003e\u003ctd\u003emarkup\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003cth\u003eAcronym\u003c/th\u003e\u003ctd\u003eSGML\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003cth\u003eGlossTerm\u003c/th\u003e\u003ctd\u003eStandard Generalized Markup Language\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003cth\u003eAbbrev\u003c/th\u003e\u003ctd\u003eISO 8879:1986\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003cth\u003eSortAs\u003c/th\u003e\u003ctd\u003eSGML\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003cth\u003eID\u003c/th\u003e\u003ctd\u003eSGML\u003c/td\u003e\u003c/tr\u003e\u003c/table\u003e\u003c/td\u003e\u003c/tr\u003e\u003c/table\u003e\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003cth\u003etitle\u003c/th\u003e\u003ctd\u003eS\u003c/td\u003e\u003c/tr\u003e\u003c/table\u003e\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003cth\u003etitle\u003c/th\u003e\u003ctd\u003eexample glossary\u003c/td\u003e\u003c/tr\u003e\u003c/table\u003e\u003c/td\u003e\u003c/tr\u003e\u003c/table\u003e\n```\n\n## Tests\n\n```bash\ncd test/\npython run_tests.py\n```\n\nTested on Python 2.7 and 3.5+.\n\n## Contributors\n\n1. Michel Mueller: [@muellermichel](https://github.com/muellermichel)\n\n\t* Added support for clubbing Array of Objects with same keys, more readable format.\n\t* Added support for adding custom `table_attributes`.\n\t* Convert now accepts unicode and bytestrings for the keyword argument \"json\".\n\t* Output now should always appear in the same order as input.\n\t* Now supports JSON Lists (at top level), including clubbing.\n\t* Now supports empty inputs and positional arguments for convert.\n\t* Python 3 support ; Added integration tests for Python 2.6, 3.4 and 3.5 such that support doesn't break.\n\t* Can now also do the proper encoding for you (disabled by default to not break backwards compatibility).\n\t* Can now handle non-JSON objects on a best-effort principle.\n\t* Now by default escapes html in text nodes to prevent XSS attacks.\n\n2. Daniel Lekic: [@lekic](https://github.com/lekic)\n\t* Fixed issue with one-item lists not rendering correctly.\n\t* General code cleanup, fixed all naming conventions and coding standards to adhere to PEP8 conventions.\n\n3. Kyle Smith: [@smithk86](https://github.com/smithk86)\n\t* Added thead and tbody tags to group header and content rows when creating a table from an array of objects.\n\n## Copyright and License\n\nThe `MIT license \u003chttps://opensource.org/licenses/MIT\u003e`_\n\nCopyright (c) 2013-2024 Varun Malhotra\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","funding_links":["https://github.com/sponsors/softvar","https://patreon.com/softvar","https://opencollective.com/softvar","https://paypal.me/softvar"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoftvar%2Fjson2html","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoftvar%2Fjson2html","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoftvar%2Fjson2html/lists"}