Javascript 美化大的一行JSON文件

Javascript 美化大的一行JSON文件,javascript,json,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.74

我有一个大的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 ...
import json
print(json.dumps(t,indent=4))
我需要的是把它当作一棵树

我试过了

然后使用以下命令:cat myfile.json |下划线print-color

它向我抛出这样一个错误:在“lax”模式下解析STDIN时出错:未定义None


关于如何实现这一点,您有什么想法吗?

在python上,您可以选择json.dump上的缩进,如下所示:

{'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 ...
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还是python中实现这一点?有在线的jsbeautifier.io,在Linux上有JSONppu如果这是在javascript中,那么有无数的npm模块可以实现这一点。谷歌“美化json”这是无效的json。在JSON中,字符串文字用双引号括起来。另外,null值应该用null来表示,而不是None。您是否无意中使用了strpython_字典并将其与JSON混淆了?Python语法不是JSON。使用json模块生成实际的json。非常感谢