{"id":13821078,"url":"https://github.com/latture/json2table","last_synced_at":"2025-05-16T12:32:27.806Z","repository":{"id":57438189,"uuid":"58727311","full_name":"latture/json2table","owner":"latture","description":"Converts JSON to an HTML table","archived":false,"fork":false,"pushed_at":"2016-10-21T22:37:42.000Z","size":26,"stargazers_count":59,"open_issues_count":5,"forks_count":16,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-09T10:08:52.743Z","etag":null,"topics":["converter","html","html-table","json","python"],"latest_commit_sha":null,"homepage":"","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/latture.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-05-13T10:07:01.000Z","updated_at":"2025-01-20T13:42:54.000Z","dependencies_parsed_at":"2022-09-16T12:40:15.556Z","dependency_job_id":null,"html_url":"https://github.com/latture/json2table","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/latture%2Fjson2table","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/latture%2Fjson2table/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/latture%2Fjson2table/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/latture%2Fjson2table/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/latture","download_url":"https://codeload.github.com/latture/json2table/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254530398,"owners_count":22086607,"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":["converter","html","html-table","json","python"],"created_at":"2024-08-04T08:01:14.776Z","updated_at":"2025-05-16T12:32:22.798Z","avatar_url":"https://github.com/latture.png","language":"Python","readme":"json2table\n==========\n\n|Build Status| |Coverage Status|\n\n.. |Build Status| image:: https://travis-ci.org/latture/json2table.svg?branch=master\n   :target: https://travis-ci.org/latture/json2table\n.. |Coverage Status| image:: https://coveralls.io/repos/github/latture/json2table/badge.svg?branch=master\n   :target: https://coveralls.io/github/latture/json2table?branch=master\n\nThis is a simple Python package that allows a JSON object to be converted to HTML. It provides a ``convert`` function that accepts a ``dict`` instance and returns a string of converted HTML. For example, the simple JSON object ``{\"key\" : \"value\"}`` can be converted to HTML via:\n\n.. code:: python\n\n    \u003e\u003e\u003e from json2table import convert\n    \u003e\u003e\u003e json_object = {\"key\" : \"value\"}\n    \u003e\u003e\u003e build_direction = \"LEFT_TO_RIGHT\"\n    \u003e\u003e\u003e table_attributes = {\"style\" : \"width:100%\"}\n    \u003e\u003e\u003e html = convert(json_object, build_direction=build_direction, table_attributes=table_attributes)\n    \u003e\u003e\u003e print(html)\n    '\u003ctable style=\"width:100%\"\u003e\u003ctr\u003e\u003cth\u003ekey\u003c/th\u003e\u003ctd\u003evalue\u003c/td\u003e\u003c/tr\u003e\u003c/table\u003e'\n\nThe resulting table will resemble\n\n+---------+-------+\n| **key** | value |\n+---------+-------+\n\nMore complex parsing is also possible. If a list of ``dict``'s provides the same list of keys, the generated HTML with gather items by key and display them in the same column.\n\n.. code:: json\n\n    {\"menu\": {\n      \"id\": \"file\",\n      \"value\": \"File\",\n        \"menuitem\": [\n          {\"value\": \"New\", \"onclick\": \"CreateNewDoc()\"},\n          {\"value\": \"Open\", \"onclick\": \"OpenDoc()\"},\n          {\"value\": \"Close\", \"onclick\": \"CloseDoc()\"}\n        ]\n      }\n    }\n\nOutput:\n\n+----------+--------------+----------------+-----------+\n| **menu** | **menuitem** | **onclick**    | **value** |\n+          +              +----------------+-----------+\n|          |              | CreateNewDoc() | New       |\n+          +              +----------------+-----------+\n|          |              | OpenDoc()      | Open      |\n+          +              +----------------+-----------+\n|          |              | CloseDoc()     | Close     |\n+          +--------------+----------------+-----------+\n|          | **id**       | file                       |\n+          +--------------+----------------+-----------+\n|          | **value**    | File                       |\n+----------+--------------+----------------+-----------+\n\nIt might, however, be more readable if we were able to build the table from top-to-bottom instead of the default left-to-right. Changing the ``build_direction`` to ``\"TOP_TO_BOTTOM\"`` yields:\n\n+----------------+-----------+-------+-----------+\n| **menu**                                       |\n+----------------+-----------+-------+-----------+\n| **menuitem**               | **id**| **value** |\n+----------------+-----------+-------+-----------+\n| **onclick**    | **value** |  file |   File    |\n+----------------+-----------+       +           +\n| CreateNewDoc() | New       |       |           | \n+----------------+-----------+       +           +\n| OpenDoc()      | Open      |       |           |\n+----------------+-----------+       +           +\n| CloseDoc()     | Close     |       |           |\n+----------------+-----------+-------+-----------+\n\nTable attributes are added via the ``table_attributes`` parameter. This parameter should be a ``dict`` of ``(key, value)`` pairs to apply to the table in the form ``key=\"value\"``. If in our simple example before we additionally wanted to apply a class attribute of ``\"table table-striped\"`` we would use the following:\n\n.. code:: python\n\n    \u003e\u003e\u003e table_attributes = {\"style\" : \"width:100%\", \"class\" : \"table table-striped\"}\n\nand convert just as before:\n\n.. code:: python\n\n    \u003e\u003e\u003e html = convert(json_object, build_direction=build_direction, table_attributes=table_attributes)\n\nDetails\n-------\nThis module provides a single ``convert`` function. It takes as input the JSON object (represented as a Python ``dict``) and, optionally, a build direction and a dictionary of table attributes to customize the generated table: \n\n``convert(json_input, build_direction=\"LEFT_TO_RIGHT\", table_attributes=None)``\n\n**Parameters**\n\njson_input : dict\n\n  JSON object to convert into HTML.\n\nbuild_direction : ``{\"TOP_TO_BOTTOM\", \"LEFT_TO_RIGHT\"}``, optional\n\n  String denoting the build direction of the table. If ``\"TOP_TO_BOTTOM\"`` child\n  objects will be appended below parents, i.e. in the subsequent row. If ``\"LEFT_TO_RIGHT\"``\n  child objects will be appended to the right of parents, i.e. in the subsequent column.\n  Default is ``\"LEFT_TO_RIGHT\"``.\n\ntable_attributes : ``dict``, optional\n\n  Dictionary of ``(key, value)`` pairs describing attributes to add to the table. \n  Each attribute is added according to the template ``key=\"value\"``. For example, \n  the table ``{ \"border\" : 1 }`` modifies the generated table tags to include \n  ``border=\"1\"`` as an attribute. The generated opening tag would look like \n  ``\u003ctable border=\"1\"\u003e``. Default is ``None``.\n\n**Returns**\n\n``str``\n\n  String of converted HTML.\n\nInstallation\n------------\nThe easiest method on installation is to use ``pip``. Simply run:\n\n::\n\n    \u003e\u003e\u003e pip install json2table\n\nIf instead the repo was cloned, navigate to the root directory of the ``json2table`` package from the command line and execute:\n\n::\n\n    \u003e\u003e\u003e python setup.py install\n\nTests\n-----\n\nIn order to verify the code is working, from the command line navigate to the ``json2table`` root directory and run:\n\n::\n\n    \u003e\u003e\u003e python -m unittest tests.test_json2table\n","funding_links":[],"categories":["Python"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flatture%2Fjson2table","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flatture%2Fjson2table","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flatture%2Fjson2table/lists"}