I've been using the JSON library for Python to get data from JSON files using Python.
我一直在使用Python的JSON库来使用Python从JSON文件中获取数据。
infoFromJson = json.loads(jsonfile)
I fully understand how to work with JSON files in Python. However, I am trying to find a way to format JSON format in a nice way.
我完全理解如何在Python中使用JSON文件。但是,我试图找到一种方法来以一种很好的方式格式化JSON格式。
I prefer to convert the JSON into a nested HTML table format.
我更喜欢将JSON转换为嵌套的HTML表格式。
I found json2html for Python, which does exactly what I just described. However, it does not actually output anything when I run the script they provide.
我发现了Python的json2html,它正是我刚才所描述的。但是,当我运行它们提供的脚本时,它实际上并没有输出任何内容。
Has anyone had experience with this tool? Or does anyone have suggestions for alternatives?
有没有人有这个工具的经验?或者有没有人有替代方案的建议?
2 个解决方案
#1
#2
0
Nowadays it's better to use json2table (at least for Python 3)
现在最好使用json2table(至少对于Python 3)
import json2table
import json
infoFromJson = json.loads(jsonfile)
build_direction = "LEFT_TO_RIGHT"
table_attributes = {"style": "width:100%"}
print(json2table.convert(infoFromJson,
build_direction=build_direction,
table_attributes=table_attributes))
#1
7
Try the following:
请尝试以下方法:
infoFromJson = json.loads(jsonfile)
print json2html.convert(json = infoFromJson)
The result from json2html.convert
is a string.
json2html.convert的结果是一个字符串。
If you don't have json2html module:
如果你没有json2html模块:
$ pip install json2html
More examples here.
这里有更多例子。
#2
0
Nowadays it's better to use json2table (at least for Python 3)
现在最好使用json2table(至少对于Python 3)
import json2table
import json
infoFromJson = json.loads(jsonfile)
build_direction = "LEFT_TO_RIGHT"
table_attributes = {"style": "width:100%"}
print(json2table.convert(infoFromJson,
build_direction=build_direction,
table_attributes=table_attributes))