Skip to content

Commit 5639ece

Browse files
author
Michel Müller
committed
Merge remote-tracking branch 'upstream/master'
2 parents 6d99c58 + e02e96a commit 5639ece

File tree

4 files changed

+97
-37
lines changed

4 files changed

+97
-37
lines changed

README.rst

Lines changed: 93 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,52 @@ Python wrapper to convert ``JSON`` into a human readable ``HTML Table`` represen
1616
Features
1717
--------
1818

19-
1. User-friendly Table fomat - easy to read and show.
20-
2. If any value of some key is array of objects, and all keys of all those objects are same, it will auto-club them instead of creating a new row for each Object within Array. For eg: ```jsonObject = {"sampleData": [ {"a":1, "b":2, "c":3}, {"a":5, "b":6, "c":7} ] }```
21-
3. Easy to style for different purposes. Pass table attributes so that generated Table can have custom attributes like class, etc..
19+
* User friendly tablular fomat, easy to read and share.
20+
* If value of the key is array of objects and all the keys are same(value of the key is a dict of list), the module will club by default. Eg.
2221

22+
.. code-block:: bash
23+
24+
input = {
25+
"sampleData": [{
26+
"a":1, "b":2, "c":3
27+
}, {
28+
"a":5, "b":6, "c":7
29+
}]
30+
}
31+
32+
will create only one row combining the results. This feature can be turned off by explicitly passing an argument ``clubbing = False``.
33+
34+
* Generated table can be provided some ``attributes`` explicitly. Eg. giving an ``id``, ``class`` or any ``data-*`` attribute.
35+
* Python 3 compatible
2336

2437
Live Demo
25-
---------
38+
----------
2639

27-
Visit `Online json2html Convertor <http://json2html.varunmalhotra.xyz/>`_
40+
`Click here <http://json2html.varunmalhotra.xyz/>`_ for the online demo.
41+
42+
List of valid arguments
43+
-----------------------
44+
45+
``json2html.convert`` - The module's ``convert`` method accepts three different types of arguments being passed.
46+
47+
===================== ================
48+
Argument Description
49+
--------------------- ----------------
50+
`json` a valid JSON
51+
--------------------- ----------------
52+
`table_attributes` `id="info-table"`/`class="bootstrap-class"`/`data-*` attributes can be applied to the generated table
53+
--------------------- ----------------
54+
`clubbing` turn clubbing of list with same keys of a dict / Array of objects with same key
55+
===================== ================
2856

2957
Installation
30-
-------------
58+
------------
3159

3260
.. code-block:: bash
3361
3462
$ pip install json2html
3563
36-
Or, Download `here <https://github.com/softvar/json2html/tarball/0.3>`_ and run ``python setup.py install`` after changing directory to `/json2html`
64+
Or, Download [here](https://github.com/softvar/json2html/releases) and run `python setup.py install` after changing directory to `/json2html`
3765

3866
Example Usage
3967
-------------
@@ -43,61 +71,82 @@ Example Usage
4371
.. code-block:: python
4472
4573
from json2html import *
46-
json2html.convert(json = {'name':'softvar','age':'22'})
74+
input = {
75+
"name": "json2html",
76+
"description": "Converts JSON to HTML tabular representation"
77+
}
78+
json2html.convert(json = input)
4779
4880
Output:
4981

5082
.. code-block:: bash
5183
52-
<table border="1"><tr><th>age</th><td>22</td></tr><tr><th>name</th><td>softvar</td></tr></table>
84+
<table border="1"><tr><th>name</th><td>json2html</td></tr><tr><th>description</th><td>converts JSON to HTML tabular representation</td></tr></table>
5385
54-
===== =====
55-
age 22
56-
name softvar
57-
===== =====
86+
============ ========================================================
87+
name json2html
88+
------------ --------------------------------------------------------
89+
description Converts JSON to HTML tabular representation
90+
============ ========================================================
5891

5992
**Example 2:** Setting custom attributes to table
6093

6194
.. code-block:: python
6295
6396
from json2html import *
64-
json2html.convert(json = {'name':'softvar','age':'22'}, table_attributes="class=\"table table-bordered table-hover\"")
97+
input = {
98+
"name": "json2html",
99+
"description": "Converts JSON to HTML tabular representation"
100+
}
101+
json2html.convert(json = input, table_attributes="id=\"info-table\" class=\"table table-bordered table-hover\"")
65102
66103
Output:
67104

68105
.. code-block:: bash
69106
70-
<table class="table table-bordered table-hover"><tr><th>age</th><td>22</td></tr><tr><th>name</th><td>softvar</td></tr></table>
107+
<table id="info-table" class="table table-bordered table-hover"><tr><th>name</th><td>json2html</td></tr><tr><th>description</th><td>Converts JSON to HTML tabular representation</td></tr></table>
71108
72109
**Example 3:** Clubbing same keys of: Array of Objects
73110

74111
.. code-block:: python
75112
76113
from json2html import *
77-
_json2conv = {"sample": [ {"a":1, "b":2, "c":3}, {"a":5, "b":6, "c":7} ] }
78-
json2html.convert(json = _json2conv)
114+
input = {
115+
"sample": [{
116+
"a":1, "b":2, "c":3
117+
}, {
118+
"a":5, "b":6, "c":7
119+
}]
120+
}
121+
json2html.convert(json = input)
79122
80123
Output:
81124

82125
.. code-block:: bash
83126
84127
<table border="1"><tr><th>sample</th><td><table border="1"><tr><th>a</th><th>c</th><th>b</th></tr><tr><td>1</td><td>3</td><td>2</td></tr><tr><td>5</td><td>7</td><td>6</td></tr></table></td></tr></table>
85128
86-
===== ===== =====
87-
a c b
88-
===== ===== =====
89-
1 3 2
90-
----- ----- -----
91-
5 7 6
92-
===== ===== =====
129+
======== ======= =======
130+
a c b
131+
-------- ------- -------
132+
1 3 2
133+
-------- ------- -------
134+
5 7 6
135+
======== ======= =======
93136

94137
**Example 4:** Each row for different key(s) of: Array of Objects
95138

96139
.. code-block:: python
97140
98141
from json2html import *
99-
_json2conv = {"sample": [ {"a":1, "b":2, "c":3}, {"1a1":5, "1b1":6, "c":7} ] }
100-
json2html.convert(json = _json2conv)
142+
input = {
143+
"sample": [{
144+
"a":1, "b":2, "c":3
145+
}, {
146+
"1a1":5, "1b1":6, "c":7
147+
}]
148+
}
149+
json2html.convert(json = input)
101150
102151
Output:
103152

@@ -111,7 +160,7 @@ Output:
111160
112161
from json2html import *
113162
114-
_json2conv = {
163+
input = {
115164
"glossary": {
116165
"title": "example glossary",
117166
"GlossDiv": {
@@ -134,7 +183,7 @@ Output:
134183
}
135184
}
136185
137-
json2html.convert(json = _json2conv)
186+
json2html.convert(json = input)
138187
139188
Output:
140189

@@ -150,11 +199,12 @@ Tests
150199
cd test/
151200
python run_tests.py
152201
202+
Tested with Python 2.6, 2.7 3.4, and 3.5.
203+
153204
Contributors
154205
------------
155206

156-
1. Michel Müller: `@muellermichel <https://github.com/muellermichel>`_
157-
* `Patch #2 <https://github.com/softvar/json2html/pull/2>`_
207+
1. Michel Mueller: [@muellermichel](https://github.com/muellermichel)
158208
* Added support for clubbing Array of Objects with same keys, more readable format.
159209
* Added support for adding custom `table_attributes`.
160210
* Convert now accepts unicode and bytestrings for the keyword argument "json".
@@ -165,9 +215,19 @@ Contributors
165215
* Can now also do the proper encoding for you (disabled by default to not break backwards compatibility).
166216
* Can now handle non-JSON objects on a best-effort principle.
167217

168-
2. Daniel Lekic: `@lekic <https://github.com/lekic>`_
169-
* `Patch #17 <https://github.com/softvar/json2html/pull/17>`_
218+
2. Daniel Lekic: [@lekic](https://github.com/lekic)
170219
* Fixed issue with one-item lists not rendering correctly.
171220
* General code cleanup, fixed all naming conventions and coding standards to adhere to PEP8 conventions.
172221

173-
Patches are highly welcomed.
222+
Copyright and License
223+
---------------------
224+
225+
The `MIT license <https://opensource.org/licenses/MIT>`_
226+
227+
Copyright (c) 2014-2017 Varun Malhotra
228+
229+
Permission 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:
230+
231+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
232+
233+
THE 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.

json2html/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
from .jsonconv import *
77

88
__author__ = 'Varun Malhotra'
9-
__version__ = '1.0.3'
9+
__version__ = '1.1.1'
1010
__license__ = 'MIT'

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
setup(
1212
name = 'json2html',
1313
packages = ['json2html'],
14-
version = '1.0.3',
14+
version = '1.1.1',
1515
install_requires=required,
1616
description = 'JSON to HTML Table Representation',
1717
long_description=open('README.rst').read(),
1818
author = 'Varun Malhotra',
1919
author_email = '[email protected]',
2020
url = 'https://github.com/softvar/json2html',
21-
download_url = 'https://github.com/softvar/json2html/tarball/1.0.3',
21+
download_url = 'https://github.com/softvar/json2html/tarball/1.1.1',
2222
keywords = ['json', 'HTML', 'Table'],
2323
license = 'MIT',
2424
classifiers = (

test/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
'''
77

88
__author__ = 'Varun Malhotra'
9-
__version__ = '1.0.3'
9+
__version__ = '1.1.1'
1010
__license__ = 'MIT'

0 commit comments

Comments
 (0)