javascript - 美化大单行JSON文件
问题描述
我有一个大的 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 ...
它一直在继续,我需要的是以某种方式将其作为一棵树。
我试过下划线-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"
}
}
]
}
推荐阅读
- flutter - Flutter 中的 delta、globalPosition、localPosition 和 primaryDelta 是什么?
- python - 如何在 Python 中保存对文件的响应?
- javascript - 将平面列表渲染“项目”传递给函数。React Native(有点 js 问题)
- javascript - 存储/重用 Ajax 响应的最佳实践
- azure-devops - 在 Microsoft 机器学习服务器上使用 Azure Devops python 工件存储库
- docker - 为什么我无法通过 tomcat 服务器访问我在 Kubernetes 集群中的应用程序?
- python - BOTO3:打印特定区域的实例信息
- python - 在 python 中打印到 .txt 文件时,有没有办法保留多行?
- mysql - Laravel 雄辩 - 使用 groupBy 并在同一个查询中
- postman - 错误:getaddrinfo ENOENT "mydomain" 在 Postman App 中是什么意思?