0

我有一个字典列表(基本上是端点的 JSON 响应)

我需要解析这 16000 行 json 对象并过滤符合条件的文档/对象,这些条件符合以下条件:其叶元素/字段:statusInfo/status不是“UP”,并且在那些过滤的对象中,只需返回 "name" , "serviceUrl","status"

例子 :

"ADMIN-V1"  "http://aws-ec2.aws.com:4435"  "Warning"

我一直在研究 JSONPath 模块,但是没有关于它的好的文档,我找不到更简单的方法。非常感谢任何指导。

这是来自 16000 行 JSON 响应的片段。

[
    {
        "id": "9c108ec5",
        "name": "USER-V2",
        "managementUrl": "http://aws-ec2.aws.com:5784/",
        "healthUrl": "http://aws-ec2.aws.com:5784/health",
        "serviceUrl": "http://aws-ec2.aws.com:5784/",
        "statusInfo": {
            "status": "UP",
            "timestamp": 1566663146681,
            "details": {
                "description": " Eureka Discovery Client",
                "status": "UP"
            }
        },
        "source": "discovery",
        "metadata": {},
        "info": {
            "component": "user",
            "description": "User REST Resource",
            "version": "2.2.1",
            "git": {
                "commit": {
                    "time": "07/27/2018 @ 15:06:55 CDT",
                    "id": "b2a1b37"
                },
                "branch": "refs/tags/v2.2.1"
            }
        }
    },
    {
        "id": "1a381f20",
        "name": "ADMIN-V1",
        "managementUrl": "http://aws-ec2.aws.com:4435/",
        "healthUrl": "http://aws-ec2.aws.com:4435/health",
        "serviceUrl": "http://aws-ec2.aws.com:4435/",
        "statusInfo": {
            "status": "Warning",
            "timestamp": 1566663146682,
            "details": {
                "description": "Spring Cloud Eureka Discovery Client",
                "status": "Warning"
            }
        },
        "source": "discovery",
        "metadata": {},
        "info": {
            "description": "Exchange Admin REST Resource",
            "api": {
                "version": "1.2.1",
                "name": "admin",
                "link": "https://app.swaggerhub.com/apis/AWSExchange/admin/1.2.1"
            },
            "implementation": "admin",
            "version": "1.1.0",
            "git": {
                "commit": {
                    "time": "01/04/2019 @ 15:36:48 UTC",
                    "id": "39d5551"
                },
                "branch": "refs/tags/v1.1.0"
            }
        }
    }
]
4

1 回答 1

1

如果您的 json 文件包含一个大数组,则您需要流式传输该文件以截断该数组。然后用于fromstream/1重建对象并随时过滤掉它们。

我自己没有代表文件来测试性能,但试试看:

$ jq --stream -n 'fromstream(1|truncate_stream(inputs))
    | select(.statusInfo.status != "UP")
    | .name, .serviceUrl, .statusInfo.status
' input.json
于 2019-08-25T00:58:25.453 回答