我有一个大的 json 结果文件,如下所示:
{'status': 200, 'result': [{'query': 'AL1 2RJ', 'result': {'postcode': 'AL1 2RJ', 'quality': 1, 'eastings': 514617, 'northings': 206084, 'country': 'England', 'nhs_ha': 'East of England', 'longitude': -0.341337, 'latitude': 51.741753, 'european_electoral_region': 'Eastern', 'prim ...
它一直持续着,我需要的是以某种方式将其作为一棵树。
我尝试过 underscore-cli
然后使用以下命令:cat myfile.json | underscore print --color
它给了我这个:Error while parsing STDIN in mode 'lax': None is not defined
关于如何实现这一目标有什么想法吗?
最佳答案
在 python 上,您可以选择 json.dumps
上的缩进,如下所示:
import json
print(json.dumps(t,indent=4))
结果是:
{
"status": 200,
"result": [
{
"query": "AL1 2RJ",
"result": {
"postcode": "AL1 2RJ",
"quality": 1,
"eastings": 514617,
"northings": 206084,
"country": "England",
"nhs_ha": "East of England",
"longitude": -0.341337,
"latitude": 51.741753,
"european_electoral_region": "Eastern"
}
}
]
}
关于javascript - 美化大一行 JSON 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53484542/